Contents | Package | Class | Tree | Deprecated | Index | Help Java 1.2 Beta 3
PREV | NEXT SHOW LISTS | HIDE LISTS

Class java.awt.swing.JLayeredPane

java.lang.Object
    |
    +----java.awt.Component
            |
            +----java.awt.Container
                    |
                    +----java.awt.swing.JComponent
                            |
                            +----java.awt.swing.JLayeredPane
Subclasses:
JDesktopPane

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.

Warning: 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 Swing1.0 applications. It will not be possible to load serialized Swing1.0 objects with future releases of Swing. The JDK1.2 release of Swing will be the compatibility baseline for the serialized form of Swing objects.


Inner Class Summary
 JLayeredPane.AccessibleJLayeredPane
The class used to obtain the accessible role for this object.
 
Inner classes inherited from class java.awt.swing.JComponent
 JComponent.AccessibleJComponent
 

Field Summary
static Integer  DEFAULT_LAYER
Convience object defining the Default layer.
static Integer  DRAG_LAYER
Convience object defining the Drag layer.
static Integer  FRAME_CONTENT_LAYER
Convience object defining the Frame Content layer.
static String  LAYER_PROPERTY
 
static Integer  MODAL_LAYER
Convience object defining the Modal layer.
static Integer  PALETTE_LAYER
Convience object defining the Palette layer.
static Integer  POPUP_LAYER
Convience object defining the Popup layer.
 
Fields inherited from class java.awt.swing.JComponent
 accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
 BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 

Constructor Summary
 JLayeredPane()
 
 

Method Summary
void  addImpl(Component comp, Object constraints, int index)
 
AccessibleContext  getAccessibleContext()
Get the AccessibleContext associated with this JComponent
int  getComponentCountInLayer(int layer)
Returns the number of children currently in layer.
Component[]  getComponentsInLayer(int layer)
Returns an array of the components in layer.
Hashtable  getComponentToLayer()
 
int  getIndexOf(Component c)
Returns the index of this Component c.
static int  getLayer(JComponent c)
This method will get the layer property on a JComponent, it does not cause any side effects like setLayer().
int  getLayer(Component c)
Returns the layer attribute for this Component c.
static JLayeredPane  getLayeredPaneAbove(Component c)
Convience method for searching above c in the component heirarchy and returns the first JLayeredPane it finds.
Integer  getObjectForLayer(int layer)
 
int  getPosition(Component c)
Relative position with the component's layer.
int  highestLayer()
Returns the highest layer value from all current children.
int  insertIndexForLayer(int layer, int position)
Primative method that determines the proper location to insert a new child based on layer and position requests.
boolean  isOptimizedDrawingEnabled()
Overridden to return false.
int  lowestLayer()
Returns the lowest layer value from all current children.
void  moveToBack(Component c)
Moves the component to position -1 within it's current layer.
void  moveToFront(Component c)
Moves the component to position 0 within it's current layer.
void  paint(Graphics g)
 
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().
void  remove(int index)
 
void  setLayer(Component c, int layer)
Sets the layer attribute on c.
void  setLayer(Component c, int layer, int position)
Sets the layer attribute on c.
void  setPosition(Component c, int position)
Moves the component to position within it's current layer.
 
Methods inherited from class java.awt.swing.JComponent
 addAncestorListener, addNotify, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInsets, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getUIClassID, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, processComponentKeyEvent, processFocusEvent, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setBounds, setDebugGraphicsOptions, setDoubleBuffered, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
 add, add, add, add, add, addContainerListener, addImpl, addNotify, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setLayout, update, validate, validateTree
 
Methods inherited from class java.awt.Component
 action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getColorModel, getComponentAt, getComponentAt, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getName, getParent, getPeer, getPreferredSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isDisplayable, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setCursor, setDropTarget, setEnabled, setFont, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, update, validate
 
Methods inherited from class java.lang.Object
 clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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
Constructor Detail

JLayeredPane

public JLayeredPane()
Method Detail

addImpl

protected void addImpl(Component comp,
                       Object constraints,
                       int index)
Overrides:
addImpl in class Container

remove

public void remove(int index)
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.

paint

public void paint(Graphics g)
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.

getAccessibleContext

public AccessibleContext getAccessibleContext()
Get the AccessibleContext associated with this JComponent
Implements:
getAccessibleContext in interface Accessible
Returns:
the AccessibleContext of this JComponent
Overrides:
getAccessibleContext in class JComponent

Contents | Package | Class | Tree | Deprecated | Index | Help Java 1.2 Beta 3
PREV | NEXT SHOW LISTS | HIDE LISTS

Submit a bug or feature
Submit comments/suggestions about new javadoc look.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.