Click here to Skip to main content
Click here to Skip to main content

Tagged as

Sliding Panel in Java

, 21 Mar 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
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. 


                               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.  


                                                        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)


About the Author

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

Comments and Discussions

-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150327.1 | Last Updated 22 Mar 2013
Article Copyright 2013 by Shubhashish_Mandal
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid