Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to avoid creating JPanel every time the user want to access it

 
Ren Shao
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, guys,
i'm building an swing application that requires switching among different panels frequently. In my current solution, when user switch to a different panel, the current panel will be lost, and recreate when the user switch back.

I know I can use a TabbedPane to solve that, but some of the program operation requires multiple steps which involves multiple panels. What I want to do is keep all my panels, do not lose them when other panels are currently displayed.

Any ideas of better solution?
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another option is to make up all of your JPanels at construction time and save each in a reference. As long as you keep this reference the JPanels will be waiting for your next call to show them. If you set a reference to null then that JPanel will be lost.
 
Daniel Mayer
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could also use the CardLayout, if I understand you correctly.
 
I'm so happy! And I wish to make this tiny ad happy too:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!