Java Reference
In-Depth Information
Although you can use your own constants for layers, use them with care—because the
system will use the predefined constants for its needs. If your constants don't fit in properly,
the components may not work as you intended.
To visualize how the different layers fit in, see Figure 8-3.
Figure 8-3. JLayeredPane layers
Working with Component Layers and Positions
Components in a JLayeredPane have both a layer and a position. When a single component is
on a layer, it's at position 0. When multiple components are on the same layer, components
added later have higher position numbers. The lower the position setting, the closer to the top
the component will appear. (This is the reverse of the layering behavior.) Figure 8-4 shows the
positions for four components on the same layer.
To rearrange components on a single layer, you can use either the public void
moveToBack(Component component) or public void moveToFront(Component component)
method. When you move a component to the front, it goes to position 0 for the layer. When
you move a component to the back, it goes to the highest position number for the layer. You
can also manually set the position with public void setPosition(Component component, int
position) . A position of -1 is automatically the bottom layer with the highest position (see
Figure 8-4).
 
Search WWH ::




Custom Search