wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes problem add panel to other panel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "problem add panel to other panel" Watch "problem add panel to other panel" New topic
Author

problem add panel to other panel

Nouf Nassri
Ranch Hand

Joined: Apr 22, 2010
Posts: 40
Hello everyone


I have a big problem I have a window that extends Jframe fenetere
contains two panels panel1 contains 2 buttons and panel2 is empty and I have two other panel extends JPanel panel3 panel4 and I like when I click button 1 i want to add 3 to the panel panel2 empty and when I click the button2 I want to add a panel4 panel2 and disappear the panel3 knowing that I work on netbeans:

button 1:



button 2:



but I do not know where is the problem.

Thank you for the help.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10426
    
    8

You need to call revalidate() and repaint() on the parent when you add/remove a child.
If your intention is to display only one panel at one time, but switch panels, the check out CardLayout


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Nouf Nassri
Ranch Hand

Joined: Apr 22, 2010
Posts: 40
Thank you for your reply I did that

but whenever I click a button I see another side of panel panel2
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10426
    
    8

revalidate() and repaint() should be called after you add the panel3
Nouf Nassri
Ranch Hand

Joined: Apr 22, 2010
Posts: 40
Maneesh Godbole wrote:revalidate() and repaint() should be called after you add the panel3


Thank you very much got the same problem

Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10426
    
    8

Post your SSCCE which we can try out in our environment.
With the code you have posted, it is difficult to figure out what is going wrong.
 
GeeCON Prague 2014
 
subject: problem add panel to other panel