See the documentation on JLayeredPane
.
Each layer is a distinct integer number. The layer attribute can be set on a Component
by passing an Integer
object during the add call.
For example:
layeredPane.add(child, JLayeredPane.DEFAULT_LAYER);
or
layeredPane.add(child, new Integer(10));
You can find the integer values of the default layer values here.
dp.add(lbl,new Integer(50));
The above adds the JLabel
component lbl
to the JDesktopPane
(which is a JLayeredPane
) with the specified layer of 50
. Components added to dp
with layers that are less than 50 will be rendered before, while components with layers greater than 50 will be rendered after -- i.e. a simple depth order, where greater layers refer to nearer components.
setLayeredPane( dp );
This sets the JFrame
represented by the ImagePaneTest
object (which probably shouldn't be a subclass) to use dp
as its layered pane. You can see how Swing top-level containers work in the relevant Java Tutorial.