Use of JLayeredPane class
Hi friend,
I am new to the java programming. I need your help to know about the one of the class of java and which is 'JLayeredPane class'. I have to make use of this java class in my java project. But I don't know anything about this JLayeredPane class of java. I also want to know about it's methods. If you have sound knowledge about JLayeredPane class of java, then please try to share it wit me. Your help would be greatly appreciable.
Re: Use of JLayeredPane class
A JLayeredPane adds depth to a JFC/Swing container, allowing components to overlap each other when needed. An Integer object specifies each component's depth in the container, where higher-numbered components sit "on top" of other components. For convenience, JLayeredPane divides the depth-range into several different layers. Putting a component into one of those layers makes it easy to ensure that components overlap properly, without having to worry about specifying numbers for specific depths.
Re: Use of JLayeredPane class
Hi,
I suggest you to refer follwing example of java which will demonstrate you the use of JLayeredPane class:
Code:
import javax.swing.JLayeredPane;
public class JLayeredPaneDM {
public static void main(String argbs[]) {
JFrame f06 = new JFrame("Sample");
f06.setDef06aultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLayeredPane desktop01 = new JDesktopPane();
desktop01.setOpaque(f06alse);
desktop01.add(new Self06InternalFrame("1"), JLayeredPane.POPUP_LAYER);
desktop01.add(new Self06InternalFrame("2"), JLayeredPane.DEFAULT_LAYER);
desktop01.add(new Self06InternalFrame("3"), JLayeredPane.PALETTE_LAYER);
f06.add(desktop01, BorderLayout.CENTER);
f06.setSize(300, 200);
f06.setVisible(true);
}}
class Self06InternalFrame extends JInternalFrame {
public Self06InternalFrame(String s1) {
getContentPane().add(new JLabel(s1), BorderLayout.CENTER);
setBounds(60, 60, 100, 100);
setResizable(true);
setClosable(true);
setTitle(s1);
setVisible(true);
setMaximizable(true);
setIconif06iable(true);
}
}
Re: Use of JLayeredPane class
Hello friend,
To use the properties of JLayeredPane class, for that you should be aware about the following it's methods:
- setPosition(Component cp, int ComponentPosition)
- setLayer(Component cp, int layer1, int ComponentPosition)
- setLayer(Component cp, int layer1)
- remove(int index1)
- putLayer(JComponent cp, int layer1)
- insertIndexForLayer(int layer1, int ComponentPosition)
Re: Use of JLayeredPane class
Hi friend,
Following example will show you how to add button using the JLayeredPane class:
Code:
import javax.swing.JLayeredPane;
public class SimpleLayersDT extends JFrame {
public SimpleLayersDT() {
super("LayeredPane Demonstration");
setSize(400, 150);
setDefaultCloseOperation(EXIT_ON_CLOSE);
JLayeredPane lp01 = getLayeredPane();
JButton top01 = new JButton();
top01.setBackground(Color.white);
top01.setBounds(30, 30, 50, 50);
JButton middle01 = new JButton();
middle01.setBackground(Color.gray);
middle01.setBounds(30, 30, 50, 50);
lp01.add(middle01, new Integer(2));
lp01.add(top01, new Integer(3));
lp01.add(bottom, new Integer(1));
}
public static void main(String[] args) {
SimpleLayersDT sl1 = new SimpleLayersDT();
sl1.setVisible(true);
}
}
Re: Use of JLayeredPane class
I suggest you to go through the following nested classes of the JLayeredPane class of java:
- JLayeredPane.AccessibleJLayeredPane
- Component.BltBufferStrategy
- JComponent.AccessibleJComponent
- Component.FlipBufferStrategy
- Container.AccessibleAWTContainer