This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP 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: 20605
60
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