![]() |
VOOZH | about |
In Java Swing, JLayeredPane is a powerful container that allows you to overlay and manage multiple components within a single container. Each component in a JLayeredPane can occupy a different layer, and you can control their positions and visibility. In this article, we are going to implement the JLayeredPane with different examples. In Java JLayeredPane is a part of javax.swing package.
JLayeredPane() : It is the default constructor of JLayeredPane, It is used to create a new JLayeredPane.
//Creating an object of JLayeredPane
JLayeredPane layeredPane = new JLayeredPane();
Methods | Description |
|---|---|
int getIndexOf(Component com) | Method for returning the index of the specified Component. |
int getPosition(Component com) | Method used to return the appropriate position of the component within the layer |
int getLayer(Component com) | Method for returning the layer attribute for the specific Component. |
add(Component com, Integer layer) | Method for returning the relative attribute for a specific component. |
moveToFront(Component com) | Navigate to the Front layer |
moveToBack(Component com) | Navigate to the backward layer. |
Java Program to demonstrate a simple JLayeredPane:
👁 Output of JLayeredPane Example 1
Implementing getIndexOf(Component com), getLayer(Component com), and getPosition(Component com) methods in JLayeredPane to get a specified layer information.
Below is the implementation of the above example: