File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes GUI Design Issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "GUI Design Issue" Watch "GUI Design Issue" New topic

GUI Design Issue

Sam Zheng
Ranch Hand

Joined: Nov 29, 2000
Posts: 61
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!
Charles Hasegawa
Ranch Hand

Joined: May 22, 2003
Posts: 117
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.
I agree. Here's the link:
subject: GUI Design Issue
It's not a secret anymore!