Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem add panel to other panel

 
Nouf Nassri
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Nouf Nassri
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
revalidate() and repaint() should be called after you add the panel3
 
Nouf Nassri
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic