Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FrameView only gets repainted when I resize the window

 
Bill Leonard
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic