jQuery in Action, 2nd edition
The moose likes Swing / AWT / SWT and the fly likes Expand/Collapse Panels Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Expand/Collapse Panels" Watch "Expand/Collapse Panels" New topic

Expand/Collapse Panels

Darrell Morello
Ranch Hand

Joined: Apr 28, 2005
Posts: 38
Hi all

Is it possible to make Expand/Collapsable panels in Java without writing huge amounts of code?

I want something like this Expand/Collapse

How would I go about it?

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
bbritta's post here might(?) do what you're after

Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
now that really is a neat bit of code
H Tasfr

Joined: Mar 28, 2010
Posts: 1
Lovely bit of code. I modified it a bit, here is a version I found more useful for my application. It is 1) entirely self contained - you pass it a created JPanel and a title String and it sets up everything and 2)not debugged at all (just so you are aware).

Hope it helps,


Campbell Ritchie

Joined: Oct 13, 2005
Posts: 40988
Thank you for the update to an old problem. And welcome to the Ranch
laila NiHai
Ranch Hand

Joined: Oct 18, 2010
Posts: 35
This works great; however, is there a trick to making the container panel or the mainframe size expand/collapse along with the expand/collapse panel? I've tried different ways, but still haven't gotten it to be perfect. Any suggestions would be greatly appreciated.
Raigedas Lietuvis

Joined: Oct 31, 2009
Posts: 16
Here is my version. Expandable by clicking on the border.

Recommended usage:
  • compile the class
  • create JFrame with netbeans
  • drag the class to the frame
  • recommended: add a panel inside the CollapsiblePanel that would be the holder for your all other controls (though the class should work even if you put several components inside it without additional holder-panel)

  • regards,
    I agree. Here's the link: http://aspose.com/file-tools
    subject: Expand/Collapse Panels