File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Updating a JPanel after change... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Updating a JPanel after change..." Watch "Updating a JPanel after change..." New topic

Updating a JPanel after change...

Kate Zoy
Ranch Hand

Joined: Feb 11, 2004
Posts: 33
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

Joined: Oct 29, 2001
Posts: 9189

call JPanel.invalidate().

[How To Ask Questions On JavaRanch]
Kate Zoy
Ranch Hand

Joined: Feb 11, 2004
Posts: 33
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

Joined: Dec 22, 2003
Posts: 38
2 panels, one for each JTable.
panel 3 holds panel1 and panel2 (both JTables)
.validate() panel3 would refresh both?
correct me if i'm wrong on this one. not testing this in code.
Kate Zoy
Ranch Hand

Joined: Feb 11, 2004
Posts: 33
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:
subject: Updating a JPanel after change...
It's not a secret anymore!