Java Reference
In-Depth Information
component is drawn on top of other components for tasks such as creating tooltip text, pop-up
menus, and dragging for drag-and-drop. You can use the system-defined layers, or you can
create your own layers.
Although initially a JLayeredPane container has no layout manager, there's nothing to stop
you from setting the layout property of the container, defeating the layering aspect of the
container.
Creating a JLayeredPane
As with the JRootPane , you'll almost never create an instance of the JLayeredPane class yourself.
When the default JRootPane is created for one of the predefined classes that implement
RootPaneContainer , the JRootPane creates a JLayeredPane for its main component area, adding
an initial content pane.
Adding Components in Layers
A layer setting for each added component manages the z-order of components within a
JLayeredPane . The higher the layer setting, the closer to the top the component will be drawn.
You can set the layer with the layout manager constraints when you add a component to a
JLayeredPane :
Integer layer = new Integer(20);
aLayeredPane.add(aComponent, layer);
You can also call the public void setLayer(Component comp, int layer) or public void
setLayer(Component comp, int layer, int position) method before adding the component
to the JLayeredPane .
aLayeredPane.setLayer(aComponent, 10);
aLayeredPane.add(aComponent);
The JLayeredPane class predefines six constants for special values. In addition, you can
find out the topmost current layer with public int c and the bottom layer with public int
lowestLayer() . Table 8-3 lists the six predefined layer constants.
Table 8-3. JLayeredPane Layer Constants
Constant
Description
FRAME_CONTENT_LAYER
Level -30,000 for holding the menu bar and content pane;
not normally used by developers
DEFAULT_LAYER
Level 0 for the normal component level
PALETTE_LAYER
Level 100 for holding floating toolbars and the like
MODAL_LAYER
Level 200 for holding pop-up dialog boxes that appear on top
of components on the default layer, on top of palettes, and
below pop-ups
POPUP_LAYER
Level 300 for holding pop-up menus and tooltips
DRAG_LAYER
Level 400 for ensuring that dragged objects remain on top
Search WWH ::




Custom Search