|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JLayeredPane
public class JLayeredPane
JLayeredPane 为 JFC/Swing 容器添加了深度,允许组件在需要时互相重叠。Integer 对象指定容器中每个组件的深度,其中编号较高的组件位于其他组件之上。有关面向任务的文档和使用分层窗格的示例,请参阅 The Java Tutorial 中的 How to Use a Layered Pane 一节。
|
|
JLayeredPane 将该深度范围分成几个不同的层。将组件放入相应的层,这样更容易确保组件正确地重叠,而不必担心为具体的深度指定编号:
JLayeredPane 的方法 moveToFront(Component)、moveToBack(Component) 和 setPosition 在组件所在层中对其进行重定位。还可以使用 setLayer 方法更改该组件的当前层。
JLayeredPane 以类似 Container 的方式管理其子级列表,但允许在其内部定义多个层。对同一层中子级的管理就像普通的 Container 对象一样,但添加的功能是,当子组件重叠时,高层中的子组件显示在低层中的子组件之上。
每一层都是一个不同的整数。可以在调用 add 的过程中通过传递 Integer 对象,从而在 Component 上设置 layer 属性。
例如:
layeredPane.add(child, JLayeredPane.DEFAULT_LAYER);
或者
layeredPane.add(child, new Integer(10));
还可以通过在 JLayeredPane 上进行如下调用在 Component 上设置 layer 属性:
layeredPaneParent.setLayer(child, 10)
JLayeredPane 是该 Component 的父组件。应该将子组件添加到父组件之前 设置 layer 属性。
编号较高的层显示在编号较低的层之上。因此,对于每个组件,使用其层编号和字母即可,有代表性的列表顺序如下所示:
5a, 5b, 5c, 2a, 2b, 2c, 1a
其中最左边的组件最接近显示区的顶部。
可以通过调用 moveToFront 或 moveToBack 将组件移入到其所在层的顶部或底部位置。
还可以直接指定某层中组件的位置。有效的位置范围是从 0 到该层中组件数减一所得的值。值 -1 指示最底层位置。值 0 指示最顶层位置。与层的编号不同,较高的位置值显示在较低 处。
注: 此序列(通过 java.awt.Container 定义)与层的编号序列相反。可是通常使用的是以下是使用方法 add(Component, layer, position) 的一些示例:调用 add(5x, 5, -1) 得到:moveToFront、moveToBack和setLayer方法。
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
使用正常的 paint/event 机制会使 1a 出现在底部,5a 出现在所有其他组件之上。
注: 这些层只是一个逻辑构造,LayoutManager 将影响此容器的所有子组件,而不管其层设置如何。
警告:Swing 不是线程安全的。有关更多信息,请参阅 Swing's Threading Policy。
警告:此类的序列化对象与以后的 Swing 版本不兼容。当前序列化支持适用于短期存储,或适用于在运行相同 Swing 版本的应用程序之间进行 RMI(Remote Method Invocation,远程方法调用)。从 1.4 版本开始,已在 java.beans 包中添加了支持所有 JavaBeansTM 长期存储的功能。请参见 XMLEncoder。
| 嵌套类摘要 | |
|---|---|
protected class |
JLayeredPane.AccessibleJLayeredPane
此类实现对 JLayeredPane 类的可访问性支持。 |
| 从类 javax.swing.JComponent 继承的嵌套类/接口 |
|---|
JComponent.AccessibleJComponent |
| 从类 java.awt.Container 继承的嵌套类/接口 |
|---|
Container.AccessibleAWTContainer |
| 从类 java.awt.Component 继承的嵌套类/接口 |
|---|
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| 字段摘要 | |
|---|---|
static Integer |
DEFAULT_LAYER
定义 Default 层的便捷对象。 |
static Integer |
DRAG_LAYER
定义 Drag 层的便捷对象。 |
static Integer |
FRAME_CONTENT_LAYER
定义 Frame Content 层的便捷对象。 |
static String |
LAYER_PROPERTY
绑定属性 |
static Integer |
MODAL_LAYER
定义 Modal 层的便捷对象。 |
static Integer |
PALETTE_LAYER
定义 Palette 层的便捷对象。 |
static Integer |
POPUP_LAYER
定义 Popup 层的便捷对象。 |
| 从类 javax.swing.JComponent 继承的字段 |
|---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
| 从类 java.awt.Component 继承的字段 |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| 从接口 java.awt.image.ImageObserver 继承的字段 |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| 构造方法摘要 | |
|---|---|
JLayeredPane()
创建新的 JLayeredPane |
|
| 方法摘要 | |
|---|---|
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)
返回与指定层关联的 Integer 对象。 |
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)
设置指定组件的 layer 属性,使之成为该层中最底部的组件。 |
void |
setLayer(Component c,
int layer,
int position)
为指定组件设置 layer 属性,并设置它在该层中的位置。 |
void |
setPosition(Component c,
int position)
将该组件移到当前层中的 position 处,其中 0 表示该层中的最顶层位置,-1 表示最底层位置。 |
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| 字段详细信息 |
|---|
public 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
JFramepublic static final String LAYER_PROPERTY
| 构造方法详细信息 |
|---|
public JLayeredPane()
| 方法详细信息 |
|---|
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)。
如果该组件不是此容器的祖先容器,并且有一个非 null 父组件,则在将该组件添加到此容器之前,从其当前父组件中移除它。
在其他所有添加方法引用此方法时,如果某个程序需要追踪每个添加到容器的请求,那么这就是要重写的方法。被重写的方法通常应该包括一个对该方法的超类版本的调用:
super.addImpl(comp, constraints, index)
Container 中的 addImplcomp - 要添加的组件constraints - 表示此组件的布局约束的对象Container.add(Component),
Container.add(Component, int),
Container.add(Component, java.lang.Object),
LayoutManager,
LayoutManager2public void remove(int index)
Container 中的 removeindex - 指定要移除组件的 int 值getIndexOf(java.awt.Component)public void removeAll()
Container 中的 removeAllContainer.add(java.awt.Component),
Container.remove(int)public boolean isOptimizedDrawingEnabled()
JComponent 中的 isOptimizedDrawingEnabledJComponent.isOptimizedDrawingEnabled()
public static void putLayer(JComponent c,
int layer)
c - 要移动的 JComponentlayer - 一个 int 值,指定要移入的层setLayer(java.awt.Component, int)public static int getLayer(JComponent c)
c - 要检查的 JComponent
public static JLayeredPane getLayeredPaneAbove(Component c)
c - 要检查的 Component
JFrame,
JRootPane
public void setLayer(Component c,
int layer)
c - 要为其设置层的 Componentlayer - 一个 int 值,指定要设置的层,其中较低编号更接近底部
public void setLayer(Component c,
int layer,
int position)
c - 要为其设置层的 Componentlayer - 一个 int 值,指定要设置的层,其中较低编号更接近底部position - 指定层中位置的 int 值,其中 0 表示最顶层位置,-1 表示最底层位置public int getLayer(Component c)
c - 要检查的 Component
public int getIndexOf(Component c)
c - 要检查的 Component
public void moveToFront(Component c)
c - 要移动的 ComponentsetPosition(Component, int)public void moveToBack(Component c)
c - 要移动的 ComponentsetPosition(Component, int)
public void setPosition(Component c,
int position)
position 处,其中 0 表示该层中的最顶层位置,-1 表示最底层位置。
注:位置编号由 java.awt.Container 定义,且与层的编号相反。较低的位置编号更接近顶层(0 为最顶层),较高的位置编号更接近底层。
c - 要移动的 Componentposition - 范围在 -1 到 N-1 之间的 int 值,其中 N 是该组件当前层中的组件数public int getPosition(Component c)
c - 要检查的 Component
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)
JComponent 中的 paintg - 要在其中进行绘制的 Graphics 上下文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)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。
JComponent 中的 paramStringpublic AccessibleContext getAccessibleContext()
Accessible 中的 getAccessibleContextJComponent 中的 getAccessibleContext
|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。