• 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

How can I destroy a JPanel component?

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suppose I have a panel and 2 buttons on it. If buttonA is pressed, a textfield component will be displayed. Similarily, when another button, buttonB is pressed, a textfield and a list components will be displayed.
I would like to know how can I destroy those previous appeared components and let other components display on the panel?
Can I display different panels depends on which button is pressed? But the problem is how can I destroy the previous appeared panel?
Thank you for your help!!!

 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JPanel inherits:
validate() from class Container which ensures that this component has a valid layout.
setVisible(boolean b) from class JComponent which shows or hides this component depending on the value of parameter b. Components in other parts of the AWT/Swing class heirarchy also have a setVisible(boolean) method available.
So, if you were to set the visibility to off, setVisible(false), then invoke validate() on your JPanel (Container), that will hopefully do the trick.
Good Luck.
[ March 13, 2002: Message edited by: Dirk Schreckmann ]
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or you could look into CardLayout... it's kinda hard to understand at first, but it encapsulates all the showing, hiding, and ordering of components... it's probably the easiest way to provide you with a way to flip between Panels on a GUI...

-Nate
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JPanel is a container. Container has a method called remove(Component c). This method removes the component from the container.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic