File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 750
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: 9188

I would use a Card Layout.

[How To Ask Questions On JavaRanch]
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 750
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
It's not a secret anymore!