Java Swing Accordion Widget

Update !!!

Please visit the latest update to this component : New Accordian Widget . It has been greatly improved.

I thought I would share an expandable Swing Sidebar of mine (also known to some as ‘floor tabbed pane’ or sometimes its known as an ‘accordion component’). I so far haven’t seen anything on the web out there that was similar to what I needed, so I built my own (Jide has one, but its not free). This is a fairly common component, and is used in applications like Outlook.

The expandable sidebar is a component that holds a number of sidebar sections. Each sidebar section is layed out maximally vertically once it has been expanded (as shown above). A section is expanded by clicking on the grey header area with the arrow.

Alternatively, while the top screenshot shows a maximal layout, an option exists for the content to be minimally laid out. Which basically means the sidebar section is only expanded to the JComponent maximum hieght. As shown below:

The code follows :

The class is the controller which holds together all these section using a BoxLayout.

Each sidebar has a number of sidebar sections. The class controls the mechanics of the event handling and layout of each section.

The SidebarSectionModel class holds model information, which is basically the component in question for the sidebar section, as well as its title and subtitle (optional).

I wanted to have a nice little arrow, so I copied some code in the BasicArrowButton class from Sun’s Swing PLAF package into a JPanel. I am not sure what the copyright implications are of this, so I would advise using your own code to generate a button or other icon to indicate opening and closing of the sideBar sections.

Finally. Here is a class to test this thing out!

Posted in Swing, Swing Components | Tagged , , , , , , , | 2 Comments

2 Responses to Java Swing Accordion Widget

  1. felixzacat says:


  2. Stacy Braxton says:

    paint(g) method in ArrowPanel does not compute.

Leave a Reply to felixzacat Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">