File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Updating a JPanel after change...

 
Kate Zoy
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JTable for each item in a JComboBox. The JTable related to the selected JComboBox item is put into a JPanel. Before adding it to the JPanel, I made sure to remove the previous table.
My problem is that when I choose a different item in the JComboBox, the new JTable won't show until I resize the window or do something to force it to refresh. How can I get it to refresh automatically?
 
Joe Ess
Bartender
Posts: 9214
9
Linux Mac OS X Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
call JPanel.invalidate().
 
Kate Zoy
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JPanel.invalidate() didn't seem to work, but JPanel.validate() did. Thanks.
However, I'm having one more issue out of this. JPanel contains two JTables. When I call JPanel.validate(), it seems to "reload" or "repaint" the first table, but not the second. Any clue on how to do this?
 
Tony Fabeets
Ranch Hand
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
2 panels, one for each JTable.
panel 3 holds panel1 and panel2 (both JTables)
frame.setContent(panel3);
.validate() panel3 would refresh both?
correct me if i'm wrong on this one. not testing this in code.
 
Kate Zoy
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are JPanels the only way to "customize" Layouts? BorderLayout, GridLayout and FlowLayout all seem so restrictive that I am at the point of having panel over panel over panel - so on and so forth - to make my GUI arrange things in a more designed and not so boxed way?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic