• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

switching between different JPanels when pressing buttons

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a problem when trying to switch to a different JPanel when you press another button on a toolbar.

The panel does not show up until I resize the window or let a JTextArea appear instead of a JPanel.
More specifically: the btnStakes currently places a JTextArea in BorderLayout.CENTER, wich works right away.
The btnContacts places my own JPanel in the center but when I press that button before I do anything else, nothign comes up.
If I resize my screen, or press the btnStakes first and then the btnContacts button, the panel does show up.
Does anyone know a good way of dynammically adding/removing panels to a layout with proper refreshing/redrawing?

I currently have the following code:
My panel:


The main screen where the toolbar and the panel should come:
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

CardLayout and JTabbedPane are options that may suit your needs.
 
Dieter Merlin
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much
this works great!
And yes, I was planning to use the JTabbedPane in my program, but it was intended for one of the inner JPanels, and I had to keep things a bit user-friendly
 
Don't touch me. And dont' touch this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic