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

clear jPanel

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use a CardLayout.
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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()?
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, thanks. works fine when calling "repaint()" for the frame on which the panels is attached.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic