This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes FrameView only gets repainted when I resize the window Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "FrameView only gets repainted when I resize the window" Watch "FrameView only gets repainted when I resize the window" New topic
Author

FrameView only gets repainted when I resize the window

Bill Leonard
Greenhorn

Joined: Mar 26, 2010
Posts: 5
My Java swing GUI doesn't repaint until I resize the window. I create a FrameView with a menuBar (with menu items whose events cause the loading of different JPanels via FrameView's setComponent) and a dummy/empty JPanel. When user selects a menu item, a custom JPanel is created and FrameView's setComponent is called with this as a parameter. When I run it and select the menu item, I don't see the new JPanel being loaded -- until I manually resize the window. Any help? Following is the code snippet:

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Whenever you add / remove a component to / from a JComponent (like JPanel) while the application is already running you need to revalidate() and repaint() the component. For AWT controls the same holds but there is no revalidate() method so invalidate() should be called instead.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
GeeCON Prague 2014
 
subject: FrameView only gets repainted when I resize the window