All Packages Class Hierarchy This Package Previous Next Index
Class java.awt.swing.JLayeredPane
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Container
|
+----java.awt.swing.JComponent
|
+----java.awt.swing.JLayeredPane
- public class JLayeredPane
- extends JComponent
- implements Accessible
JLayeredPane manages it's list of children like Container, but
allows for the definition of a several layers within itself. Children
in the same layer are managed exactly like the normal Container object,
with the added feature that children in higher layers display above
the children in lower layers.
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));
The layer attribute can also be set on a Component by calling
layeredPaneParent.setLayer(child, 10)
on the JLayeredPane that will be the parent of component. The layer
should be set before adding the child to the parent.
Higher number layers display above lower number layers.
Where numbers are the layers and letter indicate individual components:
A represenative list order looks like this:
5a, 5b, 5c, 2a, 2b, 2c, 1a
Using the method add(Component, layer, position):
Calling add(5x, 5, -1) results in:
5a, 5b, 5c, 5x, 2a, 2b, 2c, 1a
Calling add(5z, 5, 2) results in:
5a, 5b, 5z, 5c, 5x, 2a, 2b, 2c, 1a
Calling add(3a, 3, 7) results in:
5a, 5b, 5z, 5c, 5x, 3a, 2a, 2b, 2c, 1a
Using normal paint/event mechanics results in 1a appearing at the bottom
and 5a being above all other components.
Note that these layers are simply a logical construct and LayoutManagers
will affect all child components of this container without regard for
layer settings.
DEFAULT_LAYER- Convience object defining the Default layer.
DRAG_LAYER- Convience object defining the Drag layer.
FRAME_CONTENT_LAYER- Convience object defining the Frame Content layer.
LAYER_PROPERTY-
MODAL_LAYER- Convience object defining the Modal layer.
paintBackground-
PALETTE_LAYER- Convience object defining the Palette layer.
POPUP_LAYER- Convience object defining the Popup layer.
JLayeredPane()
-
addImpl(Component, Object, int)
- Adds the specified component to this container at the specified
index.
getAccessibleRole()
- Get the role of this object.
getComponentCountInLayer(int)
- Returns the number of children currently in layer.
getComponentsInLayer(int)
- Returns an array of the components in layer.
getComponentToLayer()
-
getIndexOf(Component)
- Returns the index of this Component c.
getLayer(Component)
- Returns the layer attribute for this Component c.
getLayer(JComponent)
- This method will get the layer property on a JComponent, it
does not cause any side effects like setLayer().
getLayeredPaneAbove(Component)
- Convience method for searching above c in the
component heirarchy and returns the first JLayeredPane it
finds.
getObjectForLayer(int)
-
getPosition(Component)
- Relative position with the component's layer.
highestLayer()
- Returns the highest layer value from all current children.
insertIndexForLayer(int, int)
- Primative method that determines the proper location to
insert a new child based on layer and position requests.
isOpaque()
- Returns true if this component is completely opaque.
isOptimizedDrawingEnabled()
- Overridden to return false.
lowestLayer()
- Returns the lowest layer value from all current children.
moveToBack(Component)
- Moves the component to position -1 within it's current layer.
moveToFront(Component)
- Moves the component to position 0 within it's current layer.
paint(Graphics)
- This method is invoked by Swing to draw components.
putLayer(JComponent, int)
- This method will set the layer property on a JComponent, it
does not cause any side effects like setLayer().
remove(int)
- Removes the component, specified by
index
,
from this container.
setLayer(Component, int)
- Sets the layer attribute on c.
setLayer(Component, int, int)
- Sets the layer attribute on c.
setOpaque(boolean)
-
setPosition(Component, int)
- Moves the component to position within it's current layer.
DEFAULT_LAYER
public static final Integer DEFAULT_LAYER
- Convience object defining the Default layer. Equivalent to new Integer(0).
PALETTE_LAYER
public static final Integer PALETTE_LAYER
- Convience object defining the Palette layer. Equivalent to new Integer(100).
MODAL_LAYER
public static final Integer MODAL_LAYER
- Convience object defining the Modal layer. Equivalent to new Integer(200).
POPUP_LAYER
public static final Integer POPUP_LAYER
- Convience object defining the Popup layer. Equivalent to new Integer(300).
DRAG_LAYER
public static final Integer DRAG_LAYER
- Convience object defining the Drag layer. Equivalent to new Integer(400).
FRAME_CONTENT_LAYER
public static final Integer FRAME_CONTENT_LAYER
- Convience object defining the Frame Content layer.
This layer is normally only use to positon the contentPane and menuBar
components of JFrame.
Equivalent to new Integer(-30000).
- See Also:
- JFrame
LAYER_PROPERTY
public static final String LAYER_PROPERTY
paintBackground
protected boolean paintBackground
JLayeredPane
public JLayeredPane()
addImpl
protected void addImpl(Component comp,
Object constraints,
int index)
- Adds the specified component to this container at the specified
index.
- Overrides:
- addImpl in class Container
remove
public void remove(int index)
- Removes the component, specified by
index
,
from this container.
- Overrides:
- remove in class Container
isOptimizedDrawingEnabled
public boolean isOptimizedDrawingEnabled()
- Overridden to return false. The children of a LayeredPane can overlap.
- Overrides:
- isOptimizedDrawingEnabled in class JComponent
- See Also:
- isOptimizedDrawingEnabled
putLayer
public static void putLayer(JComponent c,
int layer)
- This method will set the layer property on a JComponent, it
does not cause any side effects like setLayer(). (painting, add/remove, etc)
Normally you should use the instance method setLayer().
getLayer
public static int getLayer(JComponent c)
- This method will get the layer property on a JComponent, it
does not cause any side effects like setLayer(). (painting, add/remove, etc)
Normally you should use the instance method getLayer().
getLayeredPaneAbove
public static JLayeredPane getLayeredPaneAbove(Component c)
- Convience method for searching above c in the
component heirarchy and returns the first JLayeredPane it
finds. Will return null, in case a JLayeredPane cannot be found.
Note that all JFrames have a JLayeredPane as their rootPane.
setLayer
public void setLayer(Component c,
int layer)
- Sets the layer attribute on c. Should be called before
adding to parent.
setLayer
public void setLayer(Component c,
int layer,
int position)
- Sets the layer attribute on c.
getLayer
public int getLayer(Component c)
- Returns the layer attribute for this Component c.
getIndexOf
public int getIndexOf(Component c)
- Returns the index of this Component c.
This is the absolute index, ignoring layers.
moveToFront
public void moveToFront(Component c)
- Moves the component to position 0 within it's current layer.
moveToBack
public void moveToBack(Component c)
- Moves the component to position -1 within it's current layer.
setPosition
public void setPosition(Component c,
int position)
- Moves the component to position within it's current layer.
getPosition
public int getPosition(Component c)
- Relative position with the component's layer.
highestLayer
public int highestLayer()
- Returns the highest layer value from all current children.
Returns 0 if there are not children.
lowestLayer
public int lowestLayer()
- Returns the lowest layer value from all current children.
Returns 0 if there are not children.
getComponentCountInLayer
public int getComponentCountInLayer(int layer)
- Returns the number of children currently in layer.
getComponentsInLayer
public Component[] getComponentsInLayer(int layer)
- Returns an array of the components in layer.
setOpaque
public void setOpaque(boolean b)
isOpaque
public boolean isOpaque()
- Returns true if this component is completely opaque.
- Overrides:
- isOpaque in class JComponent
paint
public void paint(Graphics g)
- This method is invoked by Swing to draw components.
- Overrides:
- paint in class JComponent
getComponentToLayer
protected Hashtable getComponentToLayer()
getObjectForLayer
protected Integer getObjectForLayer(int layer)
insertIndexForLayer
protected int insertIndexForLayer(int layer,
int position)
- Primative method that determines the proper location to
insert a new child based on layer and position requests.
getAccessibleRole
public AccessibleRole getAccessibleRole()
- Get the role of this object.
- Returns:
- an instance of AccessibleRole describing the role of the object
- Overrides:
- getAccessibleRole in class JComponent
- See Also:
- AccessibleRole
All Packages Class Hierarchy This Package Previous Next Index
Submit a bug or feature