public class JLayeredPane extends JComponent implements Accessible
JLayeredPane增加了JFC / Swing容器的深度,允许组件在需要时重叠。
Integer对象指定容器中的每个组件的深度,其中较高编号的组件位于其他组件的“顶部”上。
对于面向任务的文档和使用分层窗格的示例,请参阅Java Tutorial中的 How to Use a Layered Pane部分。
JLayeredPane将深度范围划分为几个不同的层次。
将组件放入其中一个层可以轻松确保组件正确重叠,而无需担心指定特定深度的数字:
JLayeredPane方法moveToFront(Component) , moveToBack(Component)和setPosition可用于它的层内重新定位的组分。
setLayer方法也可用于更改组件的当前层。
JLayeredPane管理它的孩子列表,如Container ,但允许定义几个层本身。
同一层中的孩子的管理与普通的Container对象一样,其附加功能是当儿童组件重叠时,较高层的儿童显示在较低层的孩子之上。
每个层都是一个不同的整数。 所述层属性可以在被设置Component通过使Integer加载呼叫期间对象。
例如:
layeredPane.add(child, JLayeredPane.DEFAULT_LAYER);
or
layeredPane.add(child, new Integer(10));
也可以通过调用在Component上设置layer属性
layeredPaneParent.setLayer(child, 10)
在JLayeredPane那是组件的父级。
在将子添加到父项之前,应该设置该层。
较高数字层显示在较低数字层之上。 因此,使用单个组件的层和字母的数字,代表性的列表顺序将如下所示:
5a, 5b, 5c, 2a, 2b, 2c, 1a
其中最左边的组件最靠近显示器的顶部。
组件可以通过调用moveToFront或moveToBack移动到其图层中的顶部或底部位置。
层内的组件位置也可以直接指定。 有效位置的范围为0到1,小于该层中的组件数。 值-1表示最底部的位置。 值为0表示最高位置。 与层数不同,显示屏中较高的位置值较低 。
Note: This sequence (defined by java.awt.Container) is the reverse of the layer numbering sequence. Usually though, you will use以下是使用方法add(Component,layer,position)的一些示例:调用add(5x,5,-1)结果:moveToFront,moveToBack, andsetLayer.
5a, 5b, 5c, 5x, 2a, 2b, 2c, 1a
调用add(5z,5,2)导致:
5a, 5b, 5z, 5c, 5x, 2a, 2b, 2c, 1a
调用add(3a,3,7)导致:
5a, 5b, 5z, 5c, 5x, 3a, 2a, 2b, 2c, 1a
使用正常的油漆/事件力学导致1a出现在底部,5a是高于所有其他组件。
注意:这些图层只是一个逻辑结构,LayoutManagers会影响此容器的所有子组件,而不考虑图层设置。
警告: Swing不是线程安全的。 欲了解更多信息,请参阅Swing's Threading Policy 。
警告:此类的序列化对象与将来的Swing版本不兼容。 当前的序列化支持适用于运行相同版本的Swing的应用程序之间的短期存储或RMI。 从1.4开始,对所有JavaBeans的长期存储的支持已经添加到java.beans包中。 请参阅XMLEncoder 。
| Modifier and Type | Class and Description |
|---|---|
protected class |
JLayeredPane.AccessibleJLayeredPane
这个类实现了可访问性支持
JLayeredPane类。
|
JComponent.AccessibleJComponentContainer.AccessibleAWTContainerComponent.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy| Modifier and Type | Field and Description |
|---|---|
static Integer |
DEFAULT_LAYER
定义默认图层的便利对象。
|
static Integer |
DRAG_LAYER
定义拖动图层的便利对象。
|
static Integer |
FRAME_CONTENT_LAYER
定义框架内容层的便利对象。
|
static String |
LAYER_PROPERTY
绑定财产
|
static Integer |
MODAL_LAYER
定义模态层的便利对象。
|
static Integer |
PALETTE_LAYER
定义调色板层的方便对象。
|
static Integer |
POPUP_LAYER
定义Popup图层的便利对象。
|
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWaccessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH| Constructor and Description |
|---|
JLayeredPane()
创建一个新的JLayeredPane
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addImpl(Component comp, Object constraints, int index)
在指定的索引处将指定的组件添加到此容器。
|
AccessibleContext |
getAccessibleContext()
获取与此JLayeredPane关联的AccessibleContext。
|
int |
getComponentCountInLayer(int layer)
返回当前在指定图层中的子项数。
|
Component[] |
getComponentsInLayer(int layer)
返回指定图层中的组件数组。
|
protected Hashtable<Component,Integer> |
getComponentToLayer()
返回将组件映射到图层的散列表。
|
int |
getIndexOf(Component c)
返回指定Component的索引。
|
int |
getLayer(Component c)
返回指定Component的layer属性。
|
static int |
getLayer(JComponent c)
获取JComponent的layer属性,它不会导致任何类似setLayer()的副作用。
|
static JLayeredPane |
getLayeredPaneAbove(Component c)
方便的方法返回包含指定组件的第一个JLayeredPane。
|
protected Integer |
getObjectForLayer(int layer)
返回与指定图层相关联的整数对象。
|
int |
getPosition(Component c)
获取组件在其层内的相对位置。
|
int |
highestLayer()
返回所有当前子节点的最高层值。
|
protected int |
insertIndexForLayer(int layer, int position)
确定基于层和位置请求插入新孩子的正确位置的原始方法。
|
boolean |
isOptimizedDrawingEnabled()
如果窗格中的组件可以重叠,则返回false,这样使得优化的绘图变得不可能。
|
int |
lowestLayer()
返回所有当前子项的最低层值。
|
void |
moveToBack(Component c)
将组件移动到当前层中的组件底部(位置-1)。
|
void |
moveToFront(Component c)
将组件移动到当前层(位置0)中组件的顶部。
|
void |
paint(Graphics g)
在指定的图形上下文中绘制JLayeredPane。
|
protected String |
paramString()
返回此JLayeredPane的字符串表示形式。
|
static void |
putLayer(JComponent c, int layer)
设置JComponent上的layer属性。
|
void |
remove(int index)
从此窗格中删除索引的组件。
|
void |
removeAll()
从此容器中删除所有组件。
|
void |
setLayer(Component c, int layer)
设置指定组件上的图层属性,使其成为该图层中最底层的组件。
|
void |
setLayer(Component c, int layer, int position)
设置指定组件的层属性,并设置其在该层中的位置。
|
void |
setPosition(Component c, int position)
在当前层
position移动到
position ,其中0是层内的最高位置,-1是最底层的位置。
|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, 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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUIadd, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeaction, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, 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, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCyclepublic static final Integer DEFAULT_LAYER
public static final Integer PALETTE_LAYER
public static final Integer MODAL_LAYER
public static final Integer POPUP_LAYER
public static final Integer DRAG_LAYER
public static final Integer FRAME_CONTENT_LAYER
JFrame
public static final String LAYER_PROPERTY
protected void addImpl(Component comp, Object constraints, int index)
Container
addLayoutComponent方法使用指定的约束对象将组件添加到此容器的布局。
约束由正在使用的特定布局管理器定义。 例如, BorderLayout类定义了五个约束: BorderLayout.NORTH , BorderLayout.SOUTH , BorderLayout.EAST , BorderLayout.WEST和BorderLayout.CENTER 。
GridBagLayout类需要一个GridBagConstraints对象。 未能通过正确类型的约束对象结果在一个IllegalArgumentException 。
如果当前的布局管理器实现了LayoutManager2 ,那么就调用LayoutManager2.addLayoutComponent(Component,Object) 。 如果当前的布局管理器不实现LayoutManager2 ,而约束是String ,那么LayoutManager.addLayoutComponent(String,Component)就被调用了。
如果组件不是此容器的祖先,并且具有非空父项,则在将其添加到此容器之前,它将从其当前父进程中删除。
如果程序需要跟踪每个添加到容器的请求,那么这种方法将会覆盖所有其他添加方法。 一个重写方法通常应该包括调用超类的方法版本:
super.addImpl(comp, constraints, index)
该方法更改布局相关信息,因此使组件层次结构无效。 如果容器已经被显示,则此后必须验证层次结构,以显示添加的组件。
addImpl在
Container
comp - 要添加的组件
constraints - 表示此组件的布局约束的对象
index - 容器列表中插入组件的位置,其中
-1表示附加到最后
Container.add(Component) , Container.add(Component, int) , Container.add(Component, java.lang.Object) , Container.invalidate() , LayoutManager , LayoutManager2
public void remove(int index)
remove在
Container
index - 一个int指定要删除的组件
getIndexOf(java.awt.Component)
public void removeAll()
removeAll在
Container
Container.add(java.awt.Component) ,
Container.remove(int) ,
Container.invalidate()
public boolean isOptimizedDrawingEnabled()
isOptimizedDrawingEnabled在
JComponent
JComponent.isOptimizedDrawingEnabled()
public static void putLayer(JComponent c, int layer)
c - JComponent要移动
layer - 指定要将其移动到的图层的int
setLayer(java.awt.Component, int)
public static int getLayer(JComponent c)
c - 要检查的JComponent
public static JLayeredPane getLayeredPaneAbove(Component c)
public void setLayer(Component c, int layer)
c - 为图层设置的组件
layer - 一个int指定要设置的层,其中较低的数字更靠近底部
public void setLayer(Component c, int layer, int position)
c - 为图层设置的组件
layer - 一个int指定要设置的层,其中较低的数字更靠近底部
position - 一个int指定层内的位置,其中0是最上面的位置,-1是最下面的位置
public int getLayer(Component c)
c - 要检查的组件
public int getIndexOf(Component c)
c - 要检查的组件
public void moveToFront(Component c)
c - 要移动的组件
setPosition(Component, int)
public void moveToBack(Component c)
c - 要移动的组件
setPosition(Component, int)
public void setPosition(Component c, int position)
position其当前层,其中0是该层内的最高位置和-1是在最底部位置内。
注意:位置编号由java.awt.Container定义,与层编号相反。 较低的位置数字更靠近顶部(0是最上面的),而较高的位置数字更接近底部。
c - 要移动的组件
position - 在-1..N-1范围内的int,其中N是组件当前层中的组件数
public int getPosition(Component c)
c - 要检查的组件
getComponentCountInLayer(int)
public int highestLayer()
public int lowestLayer()
public int getComponentCountInLayer(int layer)
layer - 一个int指定要检查的图层
public Component[] getComponentsInLayer(int layer)
layer - 一个int指定要检查的图层
public void paint(Graphics g)
protected Hashtable<Component,Integer> getComponentToLayer()
protected Integer getObjectForLayer(int layer)
layer - 指定图层的int
protected int insertIndexForLayer(int layer,
int position)
layer - 指定图层的int
position - 指定图层内的位置的int
getIndexOf(java.awt.Component)
protected String paramString()
null 。
paramString在
JComponent
public AccessibleContext getAccessibleContext()
getAccessibleContext在界面
Accessible
getAccessibleContext在
Component
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.