Click here to Skip to main content
15,741,947 members
Articles / Desktop Programming / Swing
Posted 21 Mar 2013

Tagged as


8 bookmarked

Sliding Panel in Java

Rate me:
Please Sign up or sign in to vote.
5.00/5 (8 votes)
21 Mar 2013CPOL3 min read
Animated sliding panel in Swing.


The purpose of this article is to create an animated sliding panel to give a cool look in a Swing application. If you are a Windows user, then you must be familiar with this kind of a panel. You will be able to group / ungroup the sliding pane. Fig 1 shows a group sliding pane, at a time one panel can be in expanded mode. And in Fig 2, there are multiple panels in expanded mode. Also you will be able to set which panel can be in expand mode by default. Here we go. 

Image 1    Image 2

                               Fig 1                                                                       Fig 2

Understanding the classes

After extracting the zip file you will get the following classes:

  1. This class is responsible for doing the animation.
  2. This class hold the panel which need to slide.
  3. Title panel carries the title name along with other info such as icon, toggle button icon etc.
  4. Encapsulate both the title panel and the sliding panel.
  5. Basically its a box , to add the sliding panel.
  6. An interface to toggle the state (expand / collapse) of the sliding panel.
  7. Custom panel which will appear in slide panel.
  8. This is the testing class.  


Image 3

                                                        Fig 3 

Form Fig 3 you can see how  classes are related to each other. Yellow box represent the panel which need to slide (in our case The grey box represent the  SlideConatiner panel on which  the SlideAnimator class (responsible for animating) do the  slide transition . The red box is the title panel. TitlePanel will appear on top of each SlideComponent. Blue box wrap up the TitlePanel and SlideContainer. And the last one, the black box,  represent the SlidePaneFactory class which is basically a container to hold the SlidePanel's.

Step by Step  

It's very easy to create Sliding Pane. At first you have to create a SlidePaneFactory instance. There are two ways to create a factory instance.

//                or
SlidePaneFactory.getInstance(boolean isGroup);

The default getInstance() is used to create a ungrouped Slide Pane. To create grouped Slide Pane pass the boolean value true. Now SlidingPaneFactory is ready. Each factory represent each Sliding Pane and again each Sliding Pane can contains multiple Sliding panel. To add sliding panel into SlidePane you can use one of the following statement :

SlidePaneFactory.add((JComponent slideComponent);
//                    or
SlidePaneFactory.add((JComponent slideComponent, String title);
//                    or
SlidePaneFactory.add((JComponent slideComponent, String title, Image imageIcon);
//                    or
SlidePaneFactory.add((JComponent slideComponent, String title, Image imageIcon, boolean isExpand);

"slideComponent" is represent the Sliding Panel. The Second parameter is used to set the title of the Sliding Panel. imageIcon is used set the image of the Sliding Panel and the last one is used to set whether the panel is in expand/collapse mode.

Now the final step, add the factory instance in to your app.

Points of Interest

Very easy to create. You can easily convert the grouped slide panel to ungrouped and vice-versa and also can easily set the default state  (expand / collapse)  of each panel.

Thanks To

  • Special thanks to filthy-rich-clients . For animating the panel , I have used the code with little bit customized as per my requirement.
  • Special thanks to Dhilshuk Reddy for gradient panel .


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Software Developer (Senior)
India India
Make the world open source

Comments and Discussions

Questionusing JRadioButton Pin
Member 1260073223-Jun-16 9:39
Member 1260073223-Jun-16 9:39 
AnswerRe: using JRadioButton Pin
Shubhashish_Mandal27-Jun-16 23:55
professionalShubhashish_Mandal27-Jun-16 23:55 
Answerthanks! Pin
Member 1171163122-May-15 5:00
Member 1171163122-May-15 5:00 
SuggestionStatic preferred size issue Pin
Member 115763203-Apr-15 0:05
Member 115763203-Apr-15 0:05 
GeneralRe: Static preferred size issue Pin
Shubhashish_Mandal5-May-15 1:20
professionalShubhashish_Mandal5-May-15 1:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.