public class JLayeredPane extends JComponent implements Accessible
JLayeredPane增加深度到JFC/Swing容器,允许部分重叠,彼此需要的时候。一个
Integer对象指定的容器中的每个组件的深度,在更高的编号组成坐的“顶”,其他成分。使用分层窗格看到
How to Use a Layered Pane面向任务的文档和例子,java教程中的一部分。
|
|
JLayeredPane划分成几个不同的层的深度范围。将一个组件到一层易于保证组件恰好重叠,而不必担心指定编号为特定深度的方法:
JLayeredPane
moveToFront(Component),
moveToBack(Component)和
setPosition可以用来定位元件在其层。的
setLayer方法也可以用来改变组件的当前层。
JLayeredPane管理其孩子喜欢
Container列表,但允许一个几层的定义本身。在同一层的管理完全像正常孩子
Container对象,与添加的功能,当孩子们组成的重叠,在更高层次上显示儿童在较低层的孩子。
每一层都是一个不同的整数。图层属性可以通过在添加call.
例如通过Integer对象上设置一个Component:
layeredpane。添加(孩子,JLayeredPane。default_layer);或layeredpane。添加(孩子,新的整数(10));层属性还可以设置以
JLayeredPane是组件的父母要求
layeredpaneparent setlayer(孩子,10)。组件。层应设置之前增加孩子的父母。
更高的数字层显示在较低的数字层。因此,使用为单个组件的层和字母的数字,一个有代表性的列表顺序将看起来像这样:
5a、5b、5c,2A,2B,2C,1A在最左边的成分最接近顶部的显示器。
一个组件可以被移动到顶部或底部通过调用moveToFront或moveToBack在其层的位置。
在一层中的一个组件的位置也可以直接指定。有效位置范围从0到一个小于该层的组件数量。值1指示的最低位置。值0表示最高的位置。不同的层数,更高的位置值是降低在显示。
Note: This sequence (defined by java.awt.Container) is the reverse of the layer numbering sequence. Usually though, you will use这里所使用的方法的一些例子添加(组件、层、位置):调用add(5,5,1)的结果:moveToFront,moveToBack, andsetLayer.
5a、5b、5c,2A,2B,2C 5倍,1A调用add(5Z,5,2)的结果:
5a、5b、5c 5Z,2a,2b,5X,,2C,1A调用add(3a,3,7)的结果:
5a、5b、5c、5Z,3A,2A,2B的5倍,2C,1A使用普通油漆/事件力学结果1a中的底部和5A被所有其他组件上出现。
注:,这些层是一个简单的逻辑构造和LayoutManagers将影响该容器的所有子组件无层设置方面。
警告: Swing是线程不安全的。更多信息见Swing's Threading Policy。
警告:序列化该类的对象与以后的Swing版本不兼容。当前的序列化支持适用于短期贮藏或RMI运行相同Swing版本的应用程序之间。为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
方便的对象定义的弹出层。
|
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()
获取与此相关的accessiblecontext JLayeredPane。
|
int |
getComponentCountInLayer(int layer)
返回当前指定的层中的儿童数量。
|
Component[] |
getComponentsInLayer(int layer)
返回指定的层中的组件的数组。
|
protected Hashtable<Component,Integer> |
getComponentToLayer()
返回哈希映射组件层。
|
int |
getIndexOf(Component c)
返回指定组件的索引。
|
int |
getLayer(Component c)
返回指定组件的图层属性。
|
static int |
getLayer(JComponent c)
获取一个组件的层次性,它不会引起任何副作用,如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()
如果窗格中的组件可以重叠,则返回错误,这使得优化绘图不可能。
|
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)
设置一个组件层属性。
|
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当前层内,其中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 -距离-一个int 1 .. n-1,其中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.