JLayeredPane (Java 2 Platform SE 5.0) (original) (raw)
javax.swing
Class JLayeredPane
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JLayeredPane
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible
Direct Known Subclasses:
public class JLayeredPane
extends JComponent
implements Accessible
JLayeredPane
adds depth to a JFC/Swing container, allowing components to overlap each other when needed. An Integer
object specifies each component's depth in the container, where higher-numbered components sit "on top" of other components. For task-oriented documentation and examples of using layered panes seeHow to Use a Layered Pane, a section in The Java Tutorial.
For convenience, JLayeredPane
divides the depth-range into several different layers. Putting a component into one of those layers makes it easy to ensure that components overlap properly, without having to worry about specifying numbers for specific depths:
DEFAULT_LAYER
The standard layer, where most components go. This the bottommost layer.
PALETTE_LAYER
The palette layer sits over the default layer. Useful for floating toolbars and palettes, so they can be positioned above other components.
MODAL_LAYER
The layer used for modal dialogs. They will appear on top of any toolbars, palettes, or standard components in the container.
POPUP_LAYER
The popup layer displays above dialogs. That way, the popup windows associated with combo boxes, tooltips, and other help text will appear above the component, palette, or dialog that generated them.
DRAG_LAYER
When dragging a component, reassigning it to the drag layer ensures that it is positioned over every other component in the container. When finished dragging, it can be reassigned to its normal layer.
The JLayeredPane
methods moveToFront(Component)
, moveToBack(Component)
and setPosition
can be used to reposition a component within its layer. The setLayer
method can also be used to change the component's current layer.
Details
JLayeredPane
manages its list of children likeContainer
, 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 when children components overlap, 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 is the parent of component. The layer should be set before adding the child to the parent.
Higher number layers display above lower number layers. So, using numbers for the layers and letters for individual components, a representative list order would look like this:
5a, 5b, 5c, 2a, 2b, 2c, 1a
where the leftmost components are closest to the top of the display.
A component can be moved to the top or bottom position within its layer by calling moveToFront
or moveToBack
.
The position of a component within a layer can also be specified directly. Valid positions range from 0 up to one less than the number of components in that layer. A value of -1 indicates the bottommost position. A value of 0 indicates the topmost position. Unlike layer numbers, higher position values are lower in the display.
Note: This sequence (defined by java.awt.Container) is the reverse of the layer numbering sequence. Usually though, you will use
moveToFront
,moveToBack
, andsetLayer
.
Here are some examples 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 applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans
package. Please see XMLEncoder.
Nested Class Summary | |
---|---|
protected class | JLayeredPane.AccessibleJLayeredPane This class implements accessibility support for the JLayeredPane class. |
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container |
---|
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary | |
---|---|
static Integer | DEFAULT_LAYER Convenience object defining the Default layer. |
static Integer | DRAG_LAYER Convenience object defining the Drag layer. |
static Integer | FRAME_CONTENT_LAYER Convenience object defining the Frame Content layer. |
static String | LAYER_PROPERTY Bound property |
static Integer | MODAL_LAYER Convenience object defining the Modal layer. |
static Integer | PALETTE_LAYER Convenience object defining the Palette layer. |
static Integer | POPUP_LAYER Convenience object defining the Popup layer. |
Fields inherited from class javax.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 |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary |
---|
JLayeredPane() Create a new JLayeredPane |
Method Summary | |
---|---|
protected void | [addImpl](../../javax/swing/JLayeredPane.html#addImpl%28java.awt.Component, java.lang.Object, int%29)(Component comp,Object constraints, int index) Adds the specified component to this container at the specified index. |
AccessibleContext | getAccessibleContext() Gets the AccessibleContext associated with this JLayeredPane. |
int | getComponentCountInLayer(int layer) Returns the number of children currently in the specified layer. |
Component[] | getComponentsInLayer(int layer) Returns an array of the components in the specified layer. |
protected Hashtable<Component,Integer> | getComponentToLayer() Returns the hashtable that maps components to layers. |
int | getIndexOf(Component c) Returns the index of the specified Component. |
int | getLayer(Component c) Returns the layer attribute for the specified Component. |
static int | getLayer(JComponent c) Gets the layer property for a JComponent, it does not cause any side effects like setLayer(). |
static JLayeredPane | getLayeredPaneAbove(Component c) Convenience method that returns the first JLayeredPane which contains the specified component. |
protected Integer | getObjectForLayer(int layer) Returns the Integer object associated with a specified layer. |
int | getPosition(Component c) Get the relative position of the component within its layer. |
int | highestLayer() Returns the highest layer value from all current children. |
protected int | [insertIndexForLayer](../../javax/swing/JLayeredPane.html#insertIndexForLayer%28int, int%29)(int layer, int position) Primitive method that determines the proper location to insert a new child based on layer and position requests. |
boolean | isOptimizedDrawingEnabled() Returns false if components in the pane can overlap, which makes optimized drawing impossible. |
int | lowestLayer() Returns the lowest layer value from all current children. |
void | moveToBack(Component c) Moves the component to the bottom of the components in its current layer (position -1). |
void | moveToFront(Component c) Moves the component to the top of the components in its current layer (position 0). |
void | paint(Graphics g) Paints this JLayeredPane within the specified graphics context. |
protected String | paramString() Returns a string representation of this JLayeredPane. |
static void | [putLayer](../../javax/swing/JLayeredPane.html#putLayer%28javax.swing.JComponent, int%29)(JComponent c, int layer) Sets the layer property on a JComponent. |
void | remove(int index) Remove the indexed component from this pane. |
void | removeAll() Removes all the components from this container. |
void | [setLayer](../../javax/swing/JLayeredPane.html#setLayer%28java.awt.Component, int%29)(Component c, int layer) Sets the layer attribute on the specified component, making it the bottommost component in that layer. |
void | [setLayer](../../javax/swing/JLayeredPane.html#setLayer%28java.awt.Component, int, int%29)(Component c, int layer, int position) Sets the layer attribute for the specified component and also sets its position within that layer. |
void | [setPosition](../../javax/swing/JLayeredPane.html#setPosition%28java.awt.Component, int%29)(Component c, int position) Moves the component to position within its current layer, where 0 is the topmost position within the layer and -1 is the bottommost position. |
Methods inherited from class javax.swing.JComponent |
---|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, [contains](../../javax/swing/JComponent.html#contains%28int, int%29), createToolTip, disable, enable, [firePropertyChange](../../javax/swing/JComponent.html#firePropertyChange%28java.lang.String, boolean, boolean%29), [firePropertyChange](../../javax/swing/JComponent.html#firePropertyChange%28java.lang.String, char, char%29), [firePropertyChange](../../javax/swing/JComponent.html#firePropertyChange%28java.lang.String, int, int%29), [fireVetoableChange](../../javax/swing/JComponent.html#fireVetoableChange%28java.lang.String, java.lang.Object, java.lang.Object%29), getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, [paintImmediately](../../javax/swing/JComponent.html#paintImmediately%28int, int, int, int%29), paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, [processKeyBinding](../../javax/swing/JComponent.html#processKeyBinding%28javax.swing.KeyStroke, java.awt.event.KeyEvent, int, boolean%29), processKeyEvent, processMouseEvent, processMouseMotionEvent, [putClientProperty](../../javax/swing/JComponent.html#putClientProperty%28java.lang.Object, java.lang.Object%29), [registerKeyboardAction](../../javax/swing/JComponent.html#registerKeyboardAction%28java.awt.event.ActionListener, javax.swing.KeyStroke, int%29), [registerKeyboardAction](../../javax/swing/JComponent.html#registerKeyboardAction%28java.awt.event.ActionListener, java.lang.String, javax.swing.KeyStroke, int%29), removeAncestorListener, removeNotify, removeVetoableChangeListener, [repaint](../../javax/swing/JComponent.html#repaint%28long, int, int, int, int%29), repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, [reshape](../../javax/swing/JComponent.html#reshape%28int, int, int, int%29), revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, [setFocusTraversalKeys](../../javax/swing/JComponent.html#setFocusTraversalKeys%28int, java.util.Set%29), setFont, setForeground, setInheritsPopupMenu, [setInputMap](../../javax/swing/JComponent.html#setInputMap%28int, javax.swing.InputMap%29), setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI |
Methods inherited from class java.awt.Container |
---|
add, [add](../../java/awt/Container.html#add%28java.awt.Component, int%29), [add](../../java/awt/Container.html#add%28java.awt.Component, java.lang.Object%29), [add](../../java/awt/Container.html#add%28java.awt.Component, java.lang.Object, int%29), [add](../../java/awt/Container.html#add%28java.lang.String, java.awt.Component%29), addContainerListener, addPropertyChangeListener, [addPropertyChangeListener](../../java/awt/Container.html#addPropertyChangeListener%28java.lang.String, java.beans.PropertyChangeListener%29), applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, [findComponentAt](../../java/awt/Container.html#findComponentAt%28int, int%29), findComponentAt, getComponent, [getComponentAt](../../java/awt/Container.html#getComponentAt%28int, int%29), getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, [list](../../java/awt/Container.html#list%28java.io.PrintStream, int%29), [list](../../java/awt/Container.html#list%28java.io.PrintWriter, int%29), [locate](../../java/awt/Container.html#locate%28int, int%29), minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, removeContainerListener, [setComponentZOrder](../../java/awt/Container.html#setComponentZOrder%28java.awt.Component, int%29), setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree |
Methods inherited from class java.awt.Component |
---|
[action](../../java/awt/Component.html#action%28java.awt.Event, java.lang.Object%29), add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, [checkImage](../../java/awt/Component.html#checkImage%28java.awt.Image, java.awt.image.ImageObserver%29), [checkImage](../../java/awt/Component.html#checkImage%28java.awt.Image, int, int, java.awt.image.ImageObserver%29), [coalesceEvents](../../java/awt/Component.html#coalesceEvents%28java.awt.AWTEvent, java.awt.AWTEvent%29), contains, createImage, [createImage](../../java/awt/Component.html#createImage%28int, int%29), [createVolatileImage](../../java/awt/Component.html#createVolatileImage%28int, int%29), [createVolatileImage](../../java/awt/Component.html#createVolatileImage%28int, int, java.awt.ImageCapabilities%29), disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, byte, byte%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, double, double%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, float, float%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, long, long%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, java.lang.Object, java.lang.Object%29), [firePropertyChange](../../java/awt/Component.html#firePropertyChange%28java.lang.String, short, short%29), getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, [gotFocus](../../java/awt/Component.html#gotFocus%28java.awt.Event, java.lang.Object%29), handleEvent, hasFocus, hide, [imageUpdate](../../java/awt/Component.html#imageUpdate%28java.awt.Image, int, int, int, int, int%29), [inside](../../java/awt/Component.html#inside%28int, int%29), isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, [keyDown](../../java/awt/Component.html#keyDown%28java.awt.Event, int%29), [keyUp](../../java/awt/Component.html#keyUp%28java.awt.Event, int%29), list, list, list, location, [lostFocus](../../java/awt/Component.html#lostFocus%28java.awt.Event, java.lang.Object%29), [mouseDown](../../java/awt/Component.html#mouseDown%28java.awt.Event, int, int%29), [mouseDrag](../../java/awt/Component.html#mouseDrag%28java.awt.Event, int, int%29), [mouseEnter](../../java/awt/Component.html#mouseEnter%28java.awt.Event, int, int%29), [mouseExit](../../java/awt/Component.html#mouseExit%28java.awt.Event, int, int%29), [mouseMove](../../java/awt/Component.html#mouseMove%28java.awt.Event, int, int%29), [mouseUp](../../java/awt/Component.html#mouseUp%28java.awt.Event, int, int%29), [move](../../java/awt/Component.html#move%28int, int%29), nextFocus, paintAll, postEvent, [prepareImage](../../java/awt/Component.html#prepareImage%28java.awt.Image, java.awt.image.ImageObserver%29), [prepareImage](../../java/awt/Component.html#prepareImage%28java.awt.Image, int, int, java.awt.image.ImageObserver%29), processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, [removePropertyChangeListener](../../java/awt/Component.html#removePropertyChangeListener%28java.lang.String, java.beans.PropertyChangeListener%29), repaint, [repaint](../../java/awt/Component.html#repaint%28int, int, int, int%29), repaint, resize, [resize](../../java/awt/Component.html#resize%28int, int%29), [setBounds](../../java/awt/Component.html#setBounds%28int, int, int, int%29), setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, [setLocation](../../java/awt/Component.html#setLocation%28int, int%29), setLocation, setName, setSize, [setSize](../../java/awt/Component.html#setSize%28int, int%29), show, show, size, toString, transferFocus, transferFocusUpCycle |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, [wait](../../java/lang/Object.html#wait%28long, int%29) |
Field Detail |
---|
DEFAULT_LAYER
public static final Integer DEFAULT_LAYER
Convenience object defining the Default layer. Equivalent to new Integer(0).
PALETTE_LAYER
public static final Integer PALETTE_LAYER
Convenience object defining the Palette layer. Equivalent to new Integer(100).
MODAL_LAYER
public static final Integer MODAL_LAYER
Convenience object defining the Modal layer. Equivalent to new Integer(200).
POPUP_LAYER
public static final Integer POPUP_LAYER
Convenience object defining the Popup layer. Equivalent to new Integer(300).
DRAG_LAYER
public static final Integer DRAG_LAYER
Convenience object defining the Drag layer. Equivalent to new Integer(400).
FRAME_CONTENT_LAYER
public static final Integer FRAME_CONTENT_LAYER
Convenience 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:
LAYER_PROPERTY
public static final String LAYER_PROPERTY
Bound property
See Also:
Constructor Detail |
---|
JLayeredPane
public JLayeredPane()
Create a new JLayeredPane
Method Detail |
---|
addImpl
protected void addImpl(Component comp, Object constraints, int index)
Description copied from class: [Container](../../java/awt/Container.html#addImpl%28java.awt.Component, java.lang.Object, int%29)
Adds the specified component to this container at the specified index. This method also notifies the layout manager to add the component to this container's layout using the specified constraints object via the addLayoutComponent
method.
The constraints are defined by the particular layout manager being used. For example, the BorderLayout
class defines five constraints: BorderLayout.NORTH
,BorderLayout.SOUTH
, BorderLayout.EAST
,BorderLayout.WEST
, and BorderLayout.CENTER
.
The GridBagLayout
class requires aGridBagConstraints
object. Failure to pass the correct type of constraints object results in anIllegalArgumentException
.
If the layout manager implements both the LayoutManager
and LayoutManager2
interfaces, the LayoutManager2
methods are called.
Note that if the component already exists in this container or a child of this container, it is removed from that container before being added to this container.
This is the method to override if a program needs to track every add request to a container as all other add methods defer to this one. An overriding method should usually include a call to the superclass's version of the method:
super.addImpl(comp, constraints, index)
Overrides:
[addImpl](../../java/awt/Container.html#addImpl%28java.awt.Component, java.lang.Object, int%29)
in class [Container](../../java/awt/Container.html "class in java.awt")
Parameters:
comp
- the component to be added
constraints
- an object expressing layout constraints for this component
index
- the position in the container's list at which to insert the component, where -1
means append to the end
See Also:
Container.add(Component), [Container.add(Component, int)](../../java/awt/Container.html#add%28java.awt.Component, int%29), [Container.add(Component, java.lang.Object)](../../java/awt/Container.html#add%28java.awt.Component, java.lang.Object%29), LayoutManager, LayoutManager2
remove
public void remove(int index)
Remove the indexed component from this pane. This is the absolute index, ignoring layers.
Overrides:
[remove](../../java/awt/Container.html#remove%28int%29)
in class [Container](../../java/awt/Container.html "class in java.awt")
Parameters:
index
- an int specifying the component to remove
See Also:
getIndexOf(java.awt.Component)
removeAll
public void removeAll()
Removes all the components from this container.
Overrides:
[removeAll](../../java/awt/Container.html#removeAll%28%29)
in class [Container](../../java/awt/Container.html "class in java.awt")
Since:
1.5
See Also:
Container.add(java.awt.Component), Container.remove(int)
isOptimizedDrawingEnabled
public boolean isOptimizedDrawingEnabled()
Returns false if components in the pane can overlap, which makes optimized drawing impossible. Otherwise, returns true.
Overrides:
[isOptimizedDrawingEnabled](../../javax/swing/JComponent.html#isOptimizedDrawingEnabled%28%29)
in class [JComponent](../../javax/swing/JComponent.html "class in javax.swing")
Returns:
false if components can overlap, else true
See Also:
JComponent.isOptimizedDrawingEnabled()
putLayer
public static void putLayer(JComponent c, int layer)
Sets the layer property on a JComponent. This method does not cause any side effects like setLayer() (painting, add/remove, etc). Normally you should use the instance method setLayer(), in order to get the desired side-effects (like repainting).
Parameters:
c
- the JComponent to move
layer
- an int specifying the layer to move it to
See Also:
[setLayer(java.awt.Component, int)](../../javax/swing/JLayeredPane.html#setLayer%28java.awt.Component, int%29)
getLayer
public static int getLayer(JComponent c)
Gets the layer property for a JComponent, it does not cause any side effects like setLayer(). (painting, add/remove, etc) Normally you should use the instance method getLayer().
Parameters:
c
- the JComponent to check
Returns:
an int specifying the component's layer
getLayeredPaneAbove
public static JLayeredPane getLayeredPaneAbove(Component c)
Convenience method that returns the first JLayeredPane which contains the specified component. Note that all JFrames have a JLayeredPane at their root, so any component in a JFrame will have a JLayeredPane parent.
Parameters:
c
- the Component to check
Returns:
the JLayeredPane that contains the component, or null if no JLayeredPane is found in the component hierarchy
See Also:
setLayer
public void setLayer(Component c, int layer)
Sets the layer attribute on the specified component, making it the bottommost component in that layer. Should be called before adding to parent.
Parameters:
c
- the Component to set the layer for
layer
- an int specifying the layer to set, where lower numbers are closer to the bottom
setLayer
public void setLayer(Component c, int layer, int position)
Sets the layer attribute for the specified component and also sets its position within that layer.
Parameters:
c
- the Component to set the layer for
layer
- an int specifying the layer to set, where lower numbers are closer to the bottom
position
- an int specifying the position within the layer, where 0 is the topmost position and -1 is the bottommost position
getLayer
public int getLayer(Component c)
Returns the layer attribute for the specified Component.
Parameters:
c
- the Component to check
Returns:
an int specifying the component's current layer
getIndexOf
public int getIndexOf(Component c)
Returns the index of the specified Component. This is the absolute index, ignoring layers. Index numbers, like position numbers, have the topmost component at index zero. Larger numbers are closer to the bottom.
Parameters:
c
- the Component to check
Returns:
an int specifying the component's index
moveToFront
public void moveToFront(Component c)
Moves the component to the top of the components in its current layer (position 0).
Parameters:
c
- the Component to move
See Also:
[setPosition(Component, int)](../../javax/swing/JLayeredPane.html#setPosition%28java.awt.Component, int%29)
moveToBack
public void moveToBack(Component c)
Moves the component to the bottom of the components in its current layer (position -1).
Parameters:
c
- the Component to move
See Also:
[setPosition(Component, int)](../../javax/swing/JLayeredPane.html#setPosition%28java.awt.Component, int%29)
setPosition
public void setPosition(Component c, int position)
Moves the component to position
within its current layer, where 0 is the topmost position within the layer and -1 is the bottommost position.
Note: Position numbering is defined by java.awt.Container, and is the opposite of layer numbering. Lower position numbers are closer to the top (0 is topmost), and higher position numbers are closer to the bottom.
Parameters:
c
- the Component to move
position
- an int in the range -1..N-1, where N is the number of components in the component's current layer
getPosition
public int getPosition(Component c)
Get the relative position of the component within its layer.
Parameters:
c
- the Component to check
Returns:
an int giving the component's position, where 0 is the topmost position and the highest index value = the count count of components at that layer, minus 1
See Also:
highestLayer
public int highestLayer()
Returns the highest layer value from all current children. Returns 0 if there are no children.
Returns:
an int indicating the layer of the topmost component in the pane, or zero if there are no children
lowestLayer
public int lowestLayer()
Returns the lowest layer value from all current children. Returns 0 if there are no children.
Returns:
an int indicating the layer of the bottommost component in the pane, or zero if there are no children
getComponentCountInLayer
public int getComponentCountInLayer(int layer)
Returns the number of children currently in the specified layer.
Parameters:
layer
- an int specifying the layer to check
Returns:
an int specifying the number of components in that layer
getComponentsInLayer
public Component[] getComponentsInLayer(int layer)
Returns an array of the components in the specified layer.
Parameters:
layer
- an int specifying the layer to check
Returns:
an array of Components contained in that layer
paint
public void paint(Graphics g)
Paints this JLayeredPane within the specified graphics context.
Overrides:
[paint](../../javax/swing/JComponent.html#paint%28java.awt.Graphics%29)
in class [JComponent](../../javax/swing/JComponent.html "class in javax.swing")
Parameters:
g
- the Graphics context within which to paint
See Also:
JComponent.paintComponent(java.awt.Graphics), JComponent.paintBorder(java.awt.Graphics), JComponent.paintChildren(java.awt.Graphics), JComponent.getComponentGraphics(java.awt.Graphics), [JComponent.repaint(long, int, int, int, int)](../../javax/swing/JComponent.html#repaint%28long, int, int, int, int%29)
getComponentToLayer
protected Hashtable<Component,Integer> getComponentToLayer()
Returns the hashtable that maps components to layers.
Returns:
the Hashtable used to map components to their layers
getObjectForLayer
protected Integer getObjectForLayer(int layer)
Returns the Integer object associated with a specified layer.
Parameters:
layer
- an int specifying the layer
Returns:
an Integer object for that layer
insertIndexForLayer
protected int insertIndexForLayer(int layer, int position)
Primitive method that determines the proper location to insert a new child based on layer and position requests.
Parameters:
layer
- an int specifying the layer
position
- an int specifying the position within the layer
Returns:
an int giving the (absolute) insertion-index
See Also:
getIndexOf(java.awt.Component)
paramString
protected String paramString()
Returns a string representation of this JLayeredPane. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null
.
Overrides:
[paramString](../../javax/swing/JComponent.html#paramString%28%29)
in class [JComponent](../../javax/swing/JComponent.html "class in javax.swing")
Returns:
a string representation of this JLayeredPane.
getAccessibleContext
public AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this JLayeredPane. For layered panes, the AccessibleContext takes the form of an AccessibleJLayeredPane. A new AccessibleJLayeredPane instance is created if necessary.
Specified by:
[getAccessibleContext](../../javax/accessibility/Accessible.html#getAccessibleContext%28%29)
in interface [Accessible](../../javax/accessibility/Accessible.html "interface in javax.accessibility")
Overrides:
[getAccessibleContext](../../javax/swing/JComponent.html#getAccessibleContext%28%29)
in class [JComponent](../../javax/swing/JComponent.html "class in javax.swing")
Returns:
an AccessibleJLayeredPane that serves as the AccessibleContext of this JLayeredPane
Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 2004, 2010 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.