javax.swing
public class: JLayeredPane [javadoc |
source]
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JLayeredPane
All Implemented Interfaces:
Accessible, HasGetTransferHandler, Serializable, MenuContainer, ImageObserver
Direct Known Subclasses:
JDesktopPane
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 see
How 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 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 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
, and setLayer
.
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: Swing is not thread safe. For more
information see Swing's Threading
Policy.
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 java.beans.XMLEncoder .
Nested Class Summary: |
---|
protected class | JLayeredPane.AccessibleJLayeredPane | This class implements accessibility support for the
JLayeredPane class. It provides an implementation of the
Java Accessibility API appropriate to layered pane user-interface
elements.
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 {@link java.beans.XMLEncoder}. |
Field Summary |
---|
public static final Integer | DEFAULT_LAYER | Convenience object defining the Default layer. Equivalent to new Integer(0). |
public static final Integer | PALETTE_LAYER | Convenience object defining the Palette layer. Equivalent to new Integer(100). |
public static final Integer | MODAL_LAYER | Convenience object defining the Modal layer. Equivalent to new Integer(200). |
public static final Integer | POPUP_LAYER | Convenience object defining the Popup layer. Equivalent to new Integer(300). |
public static final Integer | DRAG_LAYER | Convenience object defining the Drag layer. Equivalent to new Integer(400). |
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). |
public static final String | LAYER_PROPERTY | Bound property |
Fields inherited from javax.swing.JComponent: |
---|
DEBUG_GRAPHICS_LOADED, ui, listenerList, paintingChild, WHEN_FOCUSED, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_IN_FOCUSED_WINDOW, UNDEFINED_CONDITION, TOOL_TIP_TEXT_KEY, focusController, accessibleContext |
Fields inherited from java.awt.Component: |
---|
peer, parent, appContext, x, y, width, height, foreground, background, font, peerFont, cursor, locale, bufferStrategy, ignoreRepaint, visible, enabled, dropTarget, popups, focusTraversalKeys, LOCK, minSize, minSizeSet, prefSize, prefSizeSet, maxSize, maxSizeSet, componentOrientation, newEventsOnly, componentListener, focusListener, hierarchyListener, hierarchyBoundsListener, keyListener, mouseListener, mouseMotionListener, mouseWheelListener, inputMethodListener, windowClosingException, actionListenerK, adjustmentListenerK, componentListenerK, containerListenerK, focusListenerK, itemListenerK, keyListenerK, mouseListenerK, mouseMotionListenerK, mouseWheelListenerK, textListenerK, ownedWindowK, windowListenerK, inputMethodListenerK, hierarchyListenerK, hierarchyBoundsListenerK, windowStateListenerK, windowFocusListenerK, eventMask, isInc, incRate, TOP_ALIGNMENT, CENTER_ALIGNMENT, BOTTOM_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, isPacked, backgroundEraseDisabled, eventCache, accessibleContext |
Method from javax.swing.JLayeredPane Summary: |
---|
addImpl, getAccessibleContext, getComponentCountInLayer, getComponentToLayer, getComponentsInLayer, getIndexOf, getLayer, getLayer, getLayeredPaneAbove, getObjectForLayer, getPosition, highestLayer, insertIndexForLayer, isOptimizedDrawingEnabled, lowestLayer, moveToBack, moveToFront, paint, paramString, putLayer, remove, removeAll, setLayer, setLayer, setPosition |
Methods from javax.swing.JComponent: |
---|
_paintImmediately, addAncestorListener, addNotify, addVetoableChangeListener, alwaysOnTop, checkIfChildObscuredBySibling, clientPropertyChanged, compWriteObjectNotify, componentInputMapChanged, computeVisibleRect, computeVisibleRect, contains, createToolTip, disable, dndDone, dropLocationForPoint, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getCreatedDoubleBuffer, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getGraphicsInvoked, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getManagingFocusBackwardTraversalKeys, getManagingFocusForwardTraversalKeys, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getWriteObjCounter, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPainting, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintForceDoubleBuffered, paintImmediately, paintImmediately, paintToOffscreen, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyBindings, processKeyBindingsForAllComponents, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, rectangleIsObscured, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, safelyGetGraphics, safelyGetGraphics, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setCreatedDoubleBuffer, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setDropLocation, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPaintingChild, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setUIProperty, setVerifyInputWhenFocusTarget, setVisible, setWriteObjCounter, shouldDebugGraphics, superProcessMouseMotionEvent, unregisterKeyboardAction, update, updateUI |
Methods from java.awt.Container: |
---|
add, add, add, add, add, addContainerListener, addImpl, addNotify, addPropertyChangeListener, addPropertyChangeListener, adjustDecendantsOnParent, adjustDescendants, adjustListeningChildren, applyComponentOrientation, areFocusTraversalKeysSet, canContainFocusOwner, checkGD, clearCurrentFocusCycleRootOnHide, clearMostRecentFocusOwnerOnHide, containsFocus, countComponents, countHierarchyMembers, createChildHierarchyEvents, createHierarchyEvents, decreaseComponentCount, deliverEvent, dispatchEventImpl, dispatchEventToSelf, doLayout, eventEnabled, findComponentAt, findComponentAt, findComponentAt, findComponentAtImpl, getAccessibleAt, getAccessibleChild, getAccessibleChildrenCount, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponentZOrder, getComponents, getComponentsSync, getComponents_NoClientCode, getContainerListeners, getDropTargetEventTarget, getFocusTraversalKeys, getFocusTraversalPolicy, getHeavyweightContainer, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMouseEventTarget, getMousePosition, getOpaqueShape, getPreferredSize, getTraversalRoot, hasHeavyweightDescendants, hasLightweightDescendants, increaseComponentCount, initializeFocusTraversalKeys, insets, invalidate, invalidateParent, invalidateTree, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, isRecursivelyVisibleUpToHeavyweightContainer, isSameOrAncestorOf, isValidateRoot, layout, lightweightPaint, lightweightPrint, list, list, locate, minimumSize, mixOnHiding, mixOnReshaping, mixOnShowing, mixOnValidating, mixOnZOrderChanging, numListening, paint, paintComponents, paintHeavyweightComponents, paramString, postProcessKeyEvent, postsOldMouseEvents, preProcessKeyEvent, preferredSize, print, printComponents, printHeavyweightComponents, processContainerEvent, processEvent, proxyEnableEvents, recursiveApplyCurrentShape, recursiveApplyCurrentShape, recursiveApplyCurrentShape, recursiveSubtractAndApplyShape, recursiveSubtractAndApplyShape, recursiveSubtractAndApplyShape, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusDownCycle, update, updateGraphicsData, validate, validateTree, validateUnconditionally |
Methods from java.awt.Component: |
---|
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, adjustListeningChildrenOnParent, applyComponentOrientation, applyCompoundShape, applyCurrentShape, areBoundsValid, areFocusTraversalKeysSet, areInputMethodsEnabled, autoProcessMouseWheel, bounds, canBeFocusOwner, canBeFocusOwnerRecursively, checkGD, checkImage, checkImage, checkTreeLock, checkWindowClosingException, clearCurrentFocusCycleRootOnHide, clearMostRecentFocusOwnerOnHide, coalesceEvents, constructComponentName, contains, contains, containsFocus, countHierarchyMembers, createBufferStrategy, createBufferStrategy, createHierarchyEvents, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, dispatchEventImpl, dispatchMouseWheelToAncestor, doLayout, enable, enable, enableEvents, enableInputMethods, eventEnabled, eventTypeEnabled, findUnderMouseInWindow, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessControlContext, getAccessibleContext, getAccessibleIndexInParent, getAccessibleStateSet, getAlignmentX, getAlignmentY, getBackBuffer, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getBoundsOp, getBufferStrategy, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getContainer, getContainingWindow, getCursor, getCursor_NoClientCode, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFocusTraversalKeys_NoIDCheck, getFont, getFontMetrics, getFont_NoClientCode, getForeground, getGraphics, getGraphicsConfiguration, getGraphicsConfiguration_NoClientCode, getGraphics_NoClientCode, getHWPeerAboveMe, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getLocationOnScreen_NoTreeLock, getLocationOnWindow, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getNativeContainer, getNextFocusCandidate, getNormalShape, getObjectLock, getOpaqueShape, getParent, getParent_NoClientCode, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSiblingIndexAbove, getSiblingIndexBelow, getSize, getSize, getToolkit, getToolkitImpl, getTraversalRoot, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, initializeFocusTraversalKeys, inside, invalidate, invalidateIfValid, invalidateParent, isAutoFocusTransferOnDisposal, isBackgroundSet, isCoalescingEnabled, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isEnabledImpl, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFocusTraversableOverridden, isFocusable, isFontSet, isForegroundSet, isInstanceOf, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isMixingNeeded, isNonOpaqueForMixing, isOpaque, isPreferredSizeSet, isRecursivelyVisible, isSameOrAncestorOf, isShowing, isValid, isVisible, isVisible_NoClientCode, keyDown, keyUp, layout, lightweightPaint, lightweightPrint, list, list, list, list, list, locate, location, lostFocus, minimumSize, mixOnHiding, mixOnReshaping, mixOnShowing, mixOnValidating, mixOnZOrderChanging, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, numListening, paint, paintAll, paintHeavyweightComponents, paramString, pointRelativeToComponent, postEvent, postsOldMouseEvents, preferredSize, prepareImage, prepareImage, print, printAll, printHeavyweightComponents, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, relocateComponent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocus, requestFocus, requestFocusHelper, requestFocusHelper, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, revalidate, setAutoFocusTransferOnDisposal, setBackground, setBounds, setBounds, setBoundsOp, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFocusTraversalKeys_NoIDCheck, setFocusable, setFont, setForeground, setGraphicsConfiguration, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setRequestFocusController, setSize, setSize, setVisible, show, show, size, subtractAndApplyShape, subtractAndApplyShapeBelowMe, toString, transferFocus, transferFocus, transferFocusBackward, transferFocusBackward, transferFocusUpCycle, update, updateCursorImmediately, updateGraphicsData, updateZOrder, validate |
Methods from java.lang.Object: |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method from javax.swing.JLayeredPane Detail: |
protected void addImpl(Component comp,
Object constraints,
int index) {
int layer;
int pos;
if(constraints instanceof Integer) {
layer = ((Integer)constraints).intValue();
setLayer(comp, layer);
} else
layer = getLayer(comp);
pos = insertIndexForLayer(layer, index);
super.addImpl(comp, constraints, pos);
comp.validate();
comp.repaint();
validateOptimizedDrawing();
}
|
public AccessibleContext getAccessibleContext() {
if (accessibleContext == null) {
accessibleContext = new AccessibleJLayeredPane();
}
return accessibleContext;
}
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. |
public int getComponentCountInLayer(int layer) {
int i, count, curLayer;
int layerCount = 0;
count = getComponentCount();
for(i = 0; i < count; i++) {
curLayer = getLayer(getComponent(i));
if(curLayer == layer) {
layerCount++;
/// Short circut the counting when we have them all
} else if(layerCount > 0 || curLayer < layer) {
break;
}
}
return layerCount;
}
Returns the number of children currently in the specified layer. |
protected Hashtable<Component, Integer> getComponentToLayer() {
if(componentToLayer == null)
componentToLayer = new Hashtable< Component,Integer >(4);
return componentToLayer;
}
Returns the hashtable that maps components to layers. |
public Component[] getComponentsInLayer(int layer) {
int i, count, curLayer;
int layerCount = 0;
Component[] results;
results = new Component[getComponentCountInLayer(layer)];
count = getComponentCount();
for(i = 0; i < count; i++) {
curLayer = getLayer(getComponent(i));
if(curLayer == layer) {
results[layerCount++] = getComponent(i);
/// Short circut the counting when we have them all
} else if(layerCount > 0 || curLayer < layer) {
break;
}
}
return results;
}
Returns an array of the components in the specified layer. |
public int getIndexOf(Component c) {
int i, count;
count = getComponentCount();
for(i = 0; i < count; i++) {
if(c == getComponent(i))
return i;
}
return -1;
}
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. |
public static int getLayer(JComponent c) {
Integer i;
if((i = (Integer)c.getClientProperty(LAYER_PROPERTY)) != null)
return i.intValue();
return DEFAULT_LAYER.intValue();
}
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(). |
public int getLayer(Component c) {
Integer i;
if(c instanceof JComponent)
i = (Integer)((JComponent)c).getClientProperty(LAYER_PROPERTY);
else
i = getComponentToLayer().get(c);
if(i == null)
return DEFAULT_LAYER.intValue();
return i.intValue();
}
Returns the layer attribute for the specified Component. |
public static JLayeredPane getLayeredPaneAbove(Component c) {
if(c == null) return null;
Component parent = c.getParent();
while(parent != null && !(parent instanceof JLayeredPane))
parent = parent.getParent();
return (JLayeredPane)parent;
}
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. |
protected Integer getObjectForLayer(int layer) {
Integer layerObj;
switch(layer) {
case 0:
layerObj = DEFAULT_LAYER;
break;
case 100:
layerObj = PALETTE_LAYER;
break;
case 200:
layerObj = MODAL_LAYER;
break;
case 300:
layerObj = POPUP_LAYER;
break;
case 400:
layerObj = DRAG_LAYER;
break;
default:
layerObj = new Integer(layer);
}
return layerObj;
}
Returns the Integer object associated with a specified layer. |
public int getPosition(Component c) {
int i, startLayer, curLayer, startLocation, pos = 0;
getComponentCount();
startLocation = getIndexOf(c);
if(startLocation == -1)
return -1;
startLayer = getLayer(c);
for(i = startLocation - 1; i >= 0; i--) {
curLayer = getLayer(getComponent(i));
if(curLayer == startLayer)
pos++;
else
return pos;
}
return pos;
}
Get the relative position of the component within its layer. |
public int highestLayer() {
if(getComponentCount() > 0)
return getLayer(getComponent(0));
return 0;
}
Returns the highest layer value from all current children.
Returns 0 if there are no children. |
protected int insertIndexForLayer(int layer,
int position) {
return insertIndexForLayer(null, layer, position);
}
Primitive method that determines the proper location to
insert a new child based on layer and position requests. |
public boolean isOptimizedDrawingEnabled() {
return optimizedDrawingPossible;
}
Returns false if components in the pane can overlap, which makes
optimized drawing impossible. Otherwise, returns true. |
public int lowestLayer() {
int count = getComponentCount();
if(count > 0)
return getLayer(getComponent(count-1));
return 0;
}
Returns the lowest layer value from all current children.
Returns 0 if there are no children. |
public void moveToBack(Component c) {
setPosition(c, -1);
}
Moves the component to the bottom of the components in its current layer
(position -1). |
public void moveToFront(Component c) {
setPosition(c, 0);
}
Moves the component to the top of the components in its current layer
(position 0). |
public void paint(Graphics g) {
if(isOpaque()) {
Rectangle r = g.getClipBounds();
Color c = getBackground();
if(c == null)
c = Color.lightGray;
g.setColor(c);
if (r != null) {
g.fillRect(r.x, r.y, r.width, r.height);
}
else {
g.fillRect(0, 0, getWidth(), getHeight());
}
}
super.paint(g);
}
Paints this JLayeredPane within the specified graphics context. |
protected String paramString() {
String optimizedDrawingPossibleString = (optimizedDrawingPossible ?
"true" : "false");
return super.paramString() +
",optimizedDrawingPossible=" + optimizedDrawingPossibleString;
}
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 . |
public static void putLayer(JComponent c,
int layer) {
/// MAKE SURE THIS AND setLayer(Component c, int layer, int position) are SYNCED
Integer layerObj;
layerObj = new Integer(layer);
c.putClientProperty(LAYER_PROPERTY, layerObj);
}
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). |
public void remove(int index) {
Component c = getComponent(index);
super.remove(index);
if (c != null && !(c instanceof JComponent)) {
getComponentToLayer().remove(c);
}
validateOptimizedDrawing();
}
Remove the indexed component from this pane.
This is the absolute index, ignoring layers. |
public void removeAll() {
Component[] children = getComponents();
Hashtable cToL = getComponentToLayer();
for (int counter = children.length - 1; counter >= 0; counter--) {
Component c = children[counter];
if (c != null && !(c instanceof JComponent)) {
cToL.remove(c);
}
}
super.removeAll();
}
Removes all the components from this container. |
public void setLayer(Component c,
int layer) {
setLayer(c, layer, -1);
}
Sets the layer attribute on the specified component,
making it the bottommost component in that layer.
Should be called before adding to parent. |
public void setLayer(Component c,
int layer,
int position) {
Integer layerObj;
layerObj = getObjectForLayer(layer);
if(layer == getLayer(c) && position == getPosition(c)) {
repaint(c.getBounds());
return;
}
/// MAKE SURE THIS AND putLayer(JComponent c, int layer) are SYNCED
if(c instanceof JComponent)
((JComponent)c).putClientProperty(LAYER_PROPERTY, layerObj);
else
getComponentToLayer().put(c, layerObj);
if(c.getParent() == null || c.getParent() != this) {
repaint(c.getBounds());
return;
}
int index = insertIndexForLayer(c, layer, position);
setComponentZOrder(c, index);
repaint(c.getBounds());
}
Sets the layer attribute for the specified component and
also sets its position within that layer. |
public void setPosition(Component c,
int position) {
setLayer(c, getLayer(c), 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. |