aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Adding and Removing JPanels Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Adding and Removing JPanels" Watch "Adding and Removing JPanels" New topic

Adding and Removing JPanels

colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
Hi, I have a JFrame, and these 2 objects:

Both Drawer1 and Drawer2 extend Drawer which extends JPanel.

First, I have to add drawer1:

Then later on, during runtime, the user might want to see drawer2 instead of drawer1.
I'm not sure how to correctly remove the drawer1 object and replace it with the drawer2 object.

Any thoughts? thanks.
Joe Ess

Joined: Oct 29, 2001
Posts: 8927

I would use a Card Layout.

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
Thanks, I never even considered it.
I've heard of it before, but never used it, and it works perfectly!
I agree. Here's the link:
subject: Adding and Removing JPanels