Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Swing- dynamic generation of panels

 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got a fair knowledge of Swing but I'm stuck
with the following problem.
I've defined a JFrame which contains 3 JPanels
laid out horizontally across and a JScrollPane containing a JTable directly below.
I need to dynamically replace the second JPanel
depending on which Button was clicked on the Navigation Panel.A common scenario.
What is the best way of doing this ? Would it be via some complex event-handling or is it a simple method call.
Could someone please point me in the right direction?
Thanks in advance
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you could check out teh CardLayout in the java.awt package.
this layout allows you to change panels like in a card deck (thus its names).
if it doesnt solve your need or you dont want to use it, you can just stick to removing and adding diffrent panels all the time as the user presses the button.
 
Harry Pfohl
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You first have to get the button event. When the button is pressed get the SWING-object of your panel. Remove all components inside and then add the new items. Don't forget to initialize the new components first.
If you have to do dynamic panels very often think about building an XML interface (see www.jeasy.de; run the Example and select the tabbedpane dynamic container). Is is build 100% dynamically because all GUI components are described in an XML file readed at runtime.
Regards
[ May 28, 2002: Message edited by: Harry Pfohl ]
[ May 28, 2002: Message edited by: Harry Pfohl ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic