• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Updating a JPanel after change...

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
call JPanel.invalidate().
 
Kate Zoy
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Do the next thing next. That’s a pretty good rule. Read the tiny ad, that’s a pretty good rule, too.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic