All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.sun.java.swing.JLayeredPane

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----com.sun.java.swing.JComponent
                           |
                           +----com.sun.java.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.


Variable Index

 o DEFAULT_LAYER
Convience object defining the Default layer.
 o DRAG_LAYER
Convience object defining the Drag layer.
 o FRAME_CONTENT_LAYER
Convience object defining the Frame Content layer.
 o LAYER_PROPERTY
 o MODAL_LAYER
Convience object defining the Modal layer.
 o paintBackground
 o PALETTE_LAYER
Convience object defining the Palette layer.
 o POPUP_LAYER
Convience object defining the Popup layer.

Constructor Index

 o JLayeredPane()

Method Index

 o addImpl(Component, Object, int)
 o getAccessibleRole()
Get the role of this object.
 o getComponentCountInLayer(int)
Returns the number of children currently in layer.
 o getComponentsInLayer(int)
Returns an array of the components in layer.
 o getComponentToLayer()
 o getIndexOf(Component)
Returns the index of this Component c.
 o getLayer(Component)
Returns the layer attribute for this Component c.
 o getLayer(JComponent)
This method will get the layer property on a JComponent, it does not cause any side effects like setLayer().
 o getLayeredPaneAbove(Component)
Convience method for searching above c in the component heirarchy and returns the first JLayeredPane it finds.
 o getObjectForLayer(int)
 o getPosition(Component)
Relative position with the component's layer.
 o highestLayer()
Returns the highest layer value from all current children.
 o insertIndexForLayer(int, int)
Primative method that determines the proper location to insert a new child based on layer and position requests.
 o isOpaque()
Returns true if this component is completely opaque.
 o isOptimizedDrawingEnabled()
Overridden to return false.
 o lowestLayer()
Returns the lowest layer value from all current children.
 o moveToBack(Component)
Moves the component to position -1 within it's current layer.
 o moveToFront(Component)
Moves the component to position 0 within it's current layer.
 o paint(Graphics)
This method is invoked by Swing to draw components.
 o putLayer(JComponent, int)
This method will set the layer property on a JComponent, it does not cause any side effects like setLayer().
 o setLayer(Component, int)
Sets the layer attribute on c.
 o setLayer(Component, int, int)
Sets the layer attribute on c.
 o setOpaque(boolean)
 o setPosition(Component, int)
Moves the component to position within it's current layer.

Variables

 o DEFAULT_LAYER
 public static final Integer DEFAULT_LAYER
Convience object defining the Default layer. Equivalent to new Integer(0).

 o PALETTE_LAYER
 public static final Integer PALETTE_LAYER
Convience object defining the Palette layer. Equivalent to new Integer(100).

 o MODAL_LAYER
 public static final Integer MODAL_LAYER
Convience object defining the Modal layer. Equivalent to new Integer(200).

 o POPUP_LAYER
 public static final Integer POPUP_LAYER
Convience object defining the Popup layer. Equivalent to new Integer(300).

 o DRAG_LAYER
 public static final Integer DRAG_LAYER
Convience object defining the Drag layer. Equivalent to new Integer(400).

 o 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
 o LAYER_PROPERTY
 public static final String LAYER_PROPERTY
 o paintBackground
 protected boolean paintBackground

Constructors

 o JLayeredPane
 public JLayeredPane()

Methods

 o addImpl
 protected void addImpl(Component comp,
                        Object constraints,
                        int index)
Overrides:
addImpl in class Container
 o isOptimizedDrawingEnabled
 public boolean isOptimizedDrawingEnabled()
Overridden to return false. The children of a LayeredPane can overlap.

Overrides:
isOptimizedDrawingEnabled in class JComponent
See Also:
isOptimizedDrawingEnabled
 o 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().

 o 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().

 o 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.

 o setLayer
 public void setLayer(Component c,
                      int layer)
Sets the layer attribute on c. Should be called before adding to parent.

 o setLayer
 public void setLayer(Component c,
                      int layer,
                      int position)
Sets the layer attribute on c.

 o getLayer
 public int getLayer(Component c)
Returns the layer attribute for this Component c.

 o getIndexOf
 public int getIndexOf(Component c)
Returns the index of this Component c. This is the absolute index, ignoring layers.

 o moveToFront
 public void moveToFront(Component c)
Moves the component to position 0 within it's current layer.

 o moveToBack
 public void moveToBack(Component c)
Moves the component to position -1 within it's current layer.

 o setPosition
 public void setPosition(Component c,
                         int position)
Moves the component to position within it's current layer.

 o getPosition
 public int getPosition(Component c)
Relative position with the component's layer.

 o highestLayer
 public int highestLayer()
Returns the highest layer value from all current children. Returns 0 if there are not children.

 o lowestLayer
 public int lowestLayer()
Returns the lowest layer value from all current children. Returns 0 if there are not children.

 o getComponentCountInLayer
 public int getComponentCountInLayer(int layer)
Returns the number of children currently in layer.

 o getComponentsInLayer
 public Component[] getComponentsInLayer(int layer)
Returns an array of the components in layer.

 o setOpaque
 public void setOpaque(boolean b)
 o isOpaque
 public boolean isOpaque()
Returns true if this component is completely opaque.

Overrides:
isOpaque in class JComponent
 o paint
 public void paint(Graphics g)
This method is invoked by Swing to draw components.

Overrides:
paint in class JComponent
 o getComponentToLayer
 protected Hashtable getComponentToLayer()
 o getObjectForLayer
 protected Integer getObjectForLayer(int layer)
 o 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.

 o 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