Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I destroy a JPanel component?

 
Jess Ishasder
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • 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!!!

 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • 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 ]
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
 
Colin Humber
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic