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, new Integer(10));
Higher number layers display above lower number layers. So, using
numbers for the layers and letters for individual components, a
representative list order would look like this:
5a, 5b, 5c, 2a, 2b, 2c, 1a
A component can be moved to the top or bottom position within its
layer by calling moveToFront or moveToBack.
The position of a component within a layer can also be specified directly.
Valid positions range from 0 up to one less than the number of
components in that layer. A value of -1 indicates the bottommost
position. A value of 0 indicates the topmost position. Unlike layer
numbers, higher position values are lower in the display.
Note: This sequence (defined by java.awt.Container) is the reverse
of the layer numbering sequence. Usually though, you will use moveToFront,
moveToBack, and setLayer.
5a, 5b, 5c, 5x, 2a, 2b, 2c, 1a
5a, 5b, 5z, 5c, 5x, 2a, 2b, 2c, 1a
5a, 5b, 5z, 5c, 5x, 3a, 2a, 2b, 2c, 1a
Note: that these layers are simply a logical construct and LayoutManagers
will affect all child components of this container without regard for
Warning: Swing is not thread safe. For more
information see Swing's Threading
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeansTM
has been added to the java.beans package.
Please see XMLEncoder .