Welcome to the user guide for the JSlideMenu Swing Component. This guide will help to get you started with this powerful interface navigation component, providing you with a unique way of presenting multiple panels to your users.
There are 2 ways to create the JSlideMenu: either using the default no-arguments constructor, which will give you an empty PanelModel, or by passing in an already created PanelModel - this will be covered later.
JSlideMenu mySlideMenu = new JSlideMenu();
A fully functioning JSlideMenu consists of a number of SlideMenuPanel classes, each containing one or more components. Typically you would create the components first, then add them to the SlideMenuPanel, which could then be added to the data model of the JSlideMenu.
The SlideMenuPanel class represents two things - a button header and a panel containing the components you add to it.
SlideMenuPanel examplePanel = new SlideMenuPanel("Examples");
The constructor takes a single String parameter. This is used as the title displayed on the button header. The font, background and text color can be changed for each header button.
To add a component to a panel, you go through the panel's content pane:
examplePanel.getContentPane().add(new JButton("Example1"));
You can also set the layout of each SlideMenuPanel through the content pane.
ActionListeners can be registered against a SlideMenuPanel. These will be informed every time the header button is clicked on - even if the panel is already open. You can use the isOpen() method to determine if a panel is open or not.
Each JSlideMenu has a data model associated with it. The data model - represented by the PanelModel class - is responsible for holding all of the panels used by a particular JSlideMenu, and also for holding any data model listeners. An event will be fired to these listeners when a panel is added or removed from the data model.
A DefaultPanelModel is created automatically when you use the no-arguments constructor of the JSlideMenu. This should be sufficient for most applications, but you can create you own data model by extending the abstract PanelModel class. Such sub-classes should always fire a PanelDataEvent when a panel is added to or removed from the data model.
To access the model of a JSlideMenu:
PanelModel model = mySlideMenu.getModel();
And to add or remove a panel from a model:
model.addPanel(panel1); model.removePanel(panel1);
Anti-aliased text draws the various elements of the JSlideMenu with smooth edges, vastly improving the look of the component. To enable this feature, use the following code:
JSlideMenu mySlideMenu = new JSlideMenu(); mySlideMenu.setAntiAliased(true);
And to disable the anti-aliasing:
mySlideMenu.setAntiAliased(false);
There is one additional method to allow you to query the current state of the anti-aliasing:
boolean isAA = mySlideMenu.isAntiAliased();
Each SlideMenuPanel you create can be assigned a different background renderer, as provided by the Renderers set of classes also from SyGem Software. For example, to achieve a "Metal-shaded" look, a gradient background renderer could be used:
BackgroundRenderer back = new GradientBackgroundRenderer(new Color(255,255,255),new Color(211,207,196)) SlideMenuPanel panel1 = new SlideMenuPanel("Testing"); panel1.setBackgroundRenderer(back);
The animation speed of the SlideMenuPanels can be easily adjusted - there are two variables to consider in the animation:
Increasing the number of frames in the animation will make the animation appear smoother, but will take longer. Similarly, increasing the delay will make the animation take longer, but larger delays may look jerky.
// Set the number of animation frames mySlideMenu.setAnimationFrames(10); // And set the animation delay mySlideMenu.setAnimationDelay(100);
The time taken for the animation is equal to the number of frames multiplied by the animation delay - in the example above, 10 frames x 100 milliseconds delay = 1000 milliseconds, or 1 second. This will produce a nice smooth animation.
Like most of the SyGem Swing Components, the JSlideMenu has been created as a JavaBean, making it simple to use in conjunction with your favourite Java IDE. All you need to do is import the JSlideMenu JAR file into the IDE, and it should become available in the component palette of your choice. Please refer to the instruction manual for your IDE for more details on using and importing JavaBeans.
I hope you enjoy using the JSlideMenu - if you need any help using this or any of our components, please email us: jslidemenu@sygem.com