Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

clear jPanel  RSS feed

 
gon to
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
i have a jpanel with jlabels added. i would like to change the panels content. unfortunately the old labels don't disappear. how can i clear the panel properly? this is my attempt which is not working:



thank you! gon
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a CardLayout.
 
Al Hollis
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or you could put a Panel inside the panel

then

topPanel.remove(insidePanel);
topPanel.revalidate();

then add a new panel in its place

topPanel.add(newInsidePanel);
topPanel.revalidate();
 
gon to
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i took a look at the cardLayout but i'm not sure if it is the thing i need. i don't have a fixed number of JLabels which are exchanged, but JLabels are dynamically created (dependend of where the user clicks) and attached. everytime the user clicks, the panel should be cleared and a new set of Jlabels should be created and attached to the panel.for this purpose it seems rather complicated to me to use cardLayout.

the second proposal is not working, same problem as before...
i wonder why the panels content is not cleared by validate() or revalidate()?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
works OK like this (some things need repaint(), others don't)

 
gon to
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, thanks. works fine when calling "repaint()" for the frame on which the panels is attached.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!