my dog learned polymorphism*
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
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: 19684
    
  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
 
Don't get me started about those stupid light bulbs.
 
subject: FrameView only gets repainted when I resize the window