• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

GUI Design Issue

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have created a GUI which consists of a JFrame and a menubar. The menu bar has several menus which corresponds to different views (JPanels). Each view displays a number of JTextfield and table. The data in each view can be expressed in either metric unit or english unit. When user selects a menuitem "JRadioButtonMenuItem" (e.g. SI Unit) contained in a unit selection menu, the data in each view should be changed accordingly to reflect the new unit. However, if the display is already in SI Unit and the SI Unit menu item is clicked, then the view remains the same.
I planned to implement this unit change feature by adding an item listener on the JRadioButtonMenuItem. When user changes the unit selection, the listener method (itemStateChanged) will update and repaint ALL views within this GUI to reflect the new unit.
The problem with this approach is that it is too costly. Remember at each instance, the GUI only shows one view, so it seems to me that I should only update and repaint the view on display. For other views, the update and repaint should be done when user switches view. Am I right? If yes, how can I update the data on a hidden view once user switches view? If no, what would be a better approach? I have a hunch that this has something to do with spontaneous repainting. But my knowledge on this aspect is quite limited.
Please help!
Sam
 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure if this would work or not, but you could try keeping a list of the panels. Then in the listener for the radio buttons, iterate through the list and call the invalidate() method on each panel. Then when each panel is redisplayed, it should refresh/repaint.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic