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

change panel added to a layoutManager...

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how can I change panel added to a layoutManager.
Here is the code
<tt>
JPanel edit = new JPanel(); <br>
CardLayout card = new CardLayout();<br>
JPanel panel = new JPanel();<br>
panel.setLayout(card);<br>
panel.add(edit,"INSERT_MODE");<br>

edit JPanel contains other GUI stuff...
when a particular event occur I want to change the edit panel with anoter one...
...I know how to manage the event handling but I am not able to change that layout.
Any suggestion?
TIA
Carlo
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
The following code is an extension to your code to show an example:
JPanel edit = new JPanel();
JPanel secondPanel = new JPanel();
JPanel blankPanel = new JPanel(); //this is going to be the blank panel. do not draw anything in it,
but create the size same as the edit panel and second panel
CardLayout card = new CardLayout();
JPanel panel = new JPanel();
panel.setLayout(card);
panel.add(edit,"INSERT_MODE");
panel.add(secondPanel,"SECOND");
panel.add(blankPanel,"BLANK");
panel.card.show(panel,"INSERT_MODE"); //default panel to be shown first time or whatever u want

Then, during the event handling, suppose you want to show secondPanel, then just show the blankPanel first and then
the secondPanel. This is to avoid repainting problems you may face.
panel.card.show(panel,"BLANK");
panel.card.show(panel,"SECOND");
Hope you get what what you want!
Shashi
 
Carlo Trani
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot Shashi but maybe I did not explain in the right way my problem.
Just to continue the reference of the previous code...
I simply want sobstitute edit panel whit a new version of "that" edit JPanel.
I know how to use show method or even others (first(), last(), next() to flib between previously added panels) but I need something different!
 
Shashi Kanta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
You mean to say you want to change the contents of Edit Panel?!
If, so before removing existing components or adding new components call the method invalidate()
then after everything has been modified call the method validate(). in some case you may need to call repaint() also after validate().
But, I suggest you use a new panel and use the help of the card layout to do the switching. If you are not using the card layout, then I don't understand why you have created it!! I got misleaded!!
regards,
Shashi
 
Carlo Trani
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Shashi! :-)
You understood perfectly, really thanks a lot for your last post! I find it really useful! You touched the problem
Bye Carlo
 
If a regular clown is funny, then a larger clown would be funnier. Math. Verified by this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic