• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Swing- dynamic generation of panels

 
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic