This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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!!!
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 ]
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...
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
JPanel is a container. Container has a method called remove(Component c). This method removes the component from the container.
Sun Certified Programmer for the Java 2 Platform.<br />Sun Certified Programmer for the Java 2 Platform, 1.4.<br />Sun Certified Web Component Developer<br />IBM Certified Specialist VisualAge for Java.<br />IBM Certified Solution Developer (OOAD w/ UML).