©
本文档使用
php.cn手册 发布
|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
上一个类 下一个类 | 框架 无框架 | |||||||||
摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 |
1 2 |
|
1 |
|
Swing 实用方法的集合。
字段摘要 |
---|
从接口 javax.swing.SwingConstants 继承的字段 |
---|
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST |
方法摘要 | |
---|---|
static Rectangle |
calculateInnerArea(JComponent c,
Rectangle r)
将指定组件的内部绘制区域的位置和大小存储在 r 中,然后返回 r 。 |
static Rectangle[] |
computeDifference(Rectangle rectA,
Rectangle rectB)
返回矩形数组的便捷方法,该矩形表示不与 rectB 重叠的 rectA 内的区域。 |
static Rectangle |
computeIntersection(int x,
int y,
int width,
int height,
Rectangle dest)
在未分配新矩形的情况下计算两个矩形的交集的便捷方法。 |
static int |
computeStringWidth(FontMetrics fm,
String str)
使用具有指定“规格”(大小)的字体计算字符串的宽度。 |
static Rectangle |
computeUnion(int x,
int y,
int width,
int height,
Rectangle dest)
在未分配新矩形的情况下计算两个矩形的并集的便捷方法。 |
static MouseEvent |
convertMouseEvent(Component source,
MouseEvent sourceEvent,
Component destination)
返回类似于 sourceEvent 的 MouseEvent,除了其 x 和 y 成员已转换到 destination 的坐标系统。 |
static Point |
convertPoint(Component source,
int x,
int y,
Component destination)
将 source 坐标系统中的点 (x,y) 转换到 destination 坐标系统。 |
static Point |
convertPoint(Component source,
Point aPoint,
Component destination)
将 source 坐标系统中的 aPoint 转换到 destination 坐标系统。 |
static void |
convertPointFromScreen(Point p,
Component c)
将一个点从屏幕坐标转换到组件的坐标系统 |
static void |
convertPointToScreen(Point p,
Component c)
将一个点从组件的坐标系统转换到屏幕坐标。 |
static Rectangle |
convertRectangle(Component source,
Rectangle aRectangle,
Component destination)
将 source 坐标系统中的矩形 aRectangle 转换到 destination 坐标系统。 |
static Component |
findFocusOwner(Component c)
已过时。 从 1.4 开始,由 KeyboardFocusManager.getFocusOwner() 取代。
|
static Accessible |
getAccessibleAt(Component c,
Point p)
如果存在,则返回本地坐标 Point 处包含的 Accessible 子对象。 |
static Accessible |
getAccessibleChild(Component c,
int i)
返回对象的第 n 个可访问子对象。 |
static int |
getAccessibleChildrenCount(Component c)
返回对象中可访问的子对象数。 |
static int |
getAccessibleIndexInParent(Component c)
获取此对象在其可访问的父对象中的索引。 |
static AccessibleStateSet |
getAccessibleStateSet(Component c)
获取此对象的状态。 |
static Container |
getAncestorNamed(String name,
Component comp)
在组件层次结构中搜索上面的 comp 的便捷方法,返回它找到的 name 第一个对象。 |
static Container |
getAncestorOfClass(Class<?> c,
Component comp)
在组件层次结构中搜索上面的 comp 的便捷方法,返回它找到的类 c 的第一个对象。 |
static Component |
getDeepestComponentAt(Component parent,
int x,
int y)
返回包含位置 x 、y 的 parent 的最深可见后代组件。 |
static Rectangle |
getLocalBounds(Component aComponent)
返回组件 aComponent 的矩形 (0,0,bounds.width,bounds.height)。 |
static Component |
getRoot(Component c)
返回当前组件树结构的根组件。 |
static JRootPane |
getRootPane(Component c)
如果 c 是一个 JRootPane 后代,则返回其 JRootPane 祖先。 |
static ActionMap |
getUIActionMap(JComponent component)
返回该 UI 在组件 component 中提供的 ActionMap。 |
static InputMap |
getUIInputMap(JComponent component,
int condition)
返回由组件 component 中的条件 condition 的 UI 提供的 InputMap。 |
static Window |
getWindowAncestor(Component c)
返回 c 的第一个 Window 祖先;如果 c 未包含在 Window 内,则返回 null 。 |
static void |
invokeAndWait(Runnable doRun)
导致 doRun.run() 在 AWT 事件指派线程上同步执行。 |
static void |
invokeLater(Runnable doRun)
导致 doRun.run() 在 AWT 事件指派线程上异步执行。 |
static boolean |
isDescendingFrom(Component a,
Component b)
如果组件 a 从组件 b 继承,则返回 true 。 |
static boolean |
isEventDispatchThread()
如果当前线程是 AWT 事件指派线程,则返回 true。 |
static boolean |
isLeftMouseButton(MouseEvent anEvent)
如果鼠标事件指定左边鼠标按键,则返回 true。 |
static boolean |
isMiddleMouseButton(MouseEvent anEvent)
如果鼠标事件指定中间鼠标按键,则返回 true。 |
static boolean |
isRectangleContainingRectangle(Rectangle a,
Rectangle b)
如果 a 包含 b ,则返回 true。 |
static boolean |
isRightMouseButton(MouseEvent anEvent)
如果鼠标事件指定右边鼠标按键,则返回 true。 |
static String |
layoutCompoundLabel(FontMetrics fm,
String text,
Icon icon,
int verticalAlignment,
int horizontalAlignment,
int verticalTextPosition,
int horizontalTextPosition,
Rectangle viewR,
Rectangle iconR,
Rectangle textR,
int textIconGap)
计算并返回图标原点的位置,文本基线的原点的位置,以及复合标签字符串的可能进行了修剪的版本。 |
static String |
layoutCompoundLabel(JComponent c,
FontMetrics fm,
String text,
Icon icon,
int verticalAlignment,
int horizontalAlignment,
int verticalTextPosition,
int horizontalTextPosition,
Rectangle viewR,
Rectangle iconR,
Rectangle textR,
int textIconGap)
计算并返回图标原点的位置,文本基线的原点的位置,以及复合标签字符串的可能进行了修剪的版本。 |
static boolean |
notifyAction(Action action,
KeyStroke ks,
KeyEvent event,
Object sender,
int modifiers)
如果启用 action (且为非 null ),则调用 action 上的 actionPerformed 。 |
static void |
paintComponent(Graphics g,
Component c,
Container p,
int x,
int y,
int w,
int h)
在指定的 Graphics 上绘制组件。 |
static void |
paintComponent(Graphics g,
Component c,
Container p,
Rectangle r)
在指定的 Graphics 上绘制组件。 |
static boolean |
processKeyBindings(KeyEvent event)
处理与 event 关联的 Component 的键绑定。 |
static void |
replaceUIActionMap(JComponent component,
ActionMap uiActionMap)
将 component 的 UI ActionMap 更改为 uiActionMap 的便捷方法。 |
static void |
replaceUIInputMap(JComponent component,
int type,
InputMap uiInputMap)
将 component 的 UI InputMap 更改为 uiInputMap 的便捷方法。 |
static void |
updateComponentTreeUI(Component c)
简单的外观更改:将树结构中的每个节点转到 updateUI() -- 也就是说,通过当前外观初始化其 UI 属性。 |
static Window |
windowForComponent(Component c)
返回 c 的第一个 Window 祖先;如果 c 未包含在 Window 内,则返回 null 。 |
从类 java.lang.Object 继承的方法 |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
方法详细信息 |
---|
1 2 |
|
a
包含 b
,则返回 true。
1 |
|
aComponent
的矩形 (0,0,bounds.width,bounds.height)。
1 |
|
c
的第一个 Window
祖先;如果 c
未包含在 Window
内,则返回 null
。
c
- 要获取其 Window
祖先的 Component
。
c
的第一个 Window
祖先;如果 c
未包含在 Window
内,则返回 null
。1 2 3 |
|
source
坐标系统中的 aPoint
转换到 destination
坐标系统。如果 source
为 null
,则假定 aPoint
位于 destination
的根组件坐标系统中。如果 destination
为 null
,则将 aPoint
转换到 source
的根组件坐标系统。如果 source
和 destination
都为 null
,则返回 aPoint
,无需进行任何转换。
1 2 3 4 |
|
source
坐标系统中的点 (x,y)
转换到 destination
坐标系统。如果 source
为 null
,则假定 (x,y)
位于 destination
的根组件坐标系统中。如果 destination
为 null
,则将 (x,y)
转换到 source
的根组件坐标系统。如果 source
和 destination
都为 null
,则返回 (x,y)
,无需进行任何转换。
1 2 3 |
|
source
坐标系统中的矩形 aRectangle
转换到 destination
坐标系统。如果 source
为 null
,则假定 aRectangle
位于 destination
的根组件坐标系统中。如果 destination
为 null
,则将 aRectangle
转换到 source
的根组件坐标系统。如果 source
和 destination
都为 null
,则返回 aRectangle
,无需进行任何转换。
1 2 |
|
comp
的便捷方法,返回它找到的类 c
的第一个对象。如果无法找到类 c
,可以返回 null
。
1 2 |
|
comp
的便捷方法,返回它找到的 name
第一个对象。如果无法找到 name
,可以返回 null
。
1 2 3 |
|
x
、y
的 parent
的最深可见后代组件。如果 parent
未包含指定位置,则返回 null
。如果 parent
不是容器,或者没有一个 parent
的可见后代包含指定位置,则返回 parent
。
parent
- 开始该搜索的根组件x
- 该 x 目标位置y
- 该 y 目标位置1 2 3 |
|
sourceEvent
的 MouseEvent,除了其 x 和 y 成员已转换到 destination
的坐标系统。如果 source
为 null
,则假定已将 sourceEvent
x 和 y 成员转换到 destination
的根组件坐标系统。如果 destination
为 null
,则返回的 MouseEvent 将位于 source
的坐标系统中。sourceEvent
不会更改。返回一个新事件。返回事件的 source
字段将被设置为 destination
。如果目标为非 null
,则在不更改源的情况下使用 translateMouseEvent() 方法将鼠标事件从一个组件转换到另一个组件。
1 2 |
|
p
- 一个 Point 对象(已转换到新坐标系统)c
- 一个 Component 对象1 2 |
|
p
- 一个 Point 对象(已转换到新坐标系统)c
- 一个 Component 对象1 |
|
c
的第一个 Window
祖先;如果 c
未包含在 Window
内,则返回 null
。
注:此方法与 getWindowAncestor
提供的功能相同。
c
- 要获取其 Window
祖先的 Component
。
c
的第一个 Window
祖先;如果 c
未包含在 Window
内,则返回 null
。1 2 |
|
a
从组件 b
继承,则返回 true
。
1 2 3 4 5 |
|
x
- 第一个矩形的左上顶点的 X 坐标y
- 第一个矩形的左上顶点的 Y 坐标width
- 第一个矩形的宽度height
- 第一个矩形的高度dest
- 第二个矩形
dest
,已改为指定交集1 2 3 4 5 |
|
x
- 第一个矩形的 x 坐标y
- 第一个矩形的 y 坐标width
- 第一个矩形的宽度height
- 第一个矩形的高度dest
- 第二个矩形的坐标;在此矩形中返回两个矩形的并集
dest
Rectangle
1 2 |
|
rectB
重叠的 rectA
内的区域。如果两个矩形不重叠,则返回一个空数组。
1 |
|
anEvent
- 一个 MouseEvent 对象
1 |
|
anEvent
- 一个 MouseEvent 对象
1 |
|
anEvent
- 一个 MouseEvent 对象
1 2 |
|
fm
- 用来计算的 FontMetrics 对象str
- 要计算的字符串
1 2 3 4 5 6 7 8 9 10 11 12 |
|
1 2 3 4 5 6 7 8 9 10 11 |
|
1 2 3 4 5 6 7 |
|
Graphics
上绘制组件。此方法主要用于呈现不作为可见包含层次结构的一部分而存在,但用于呈现的 Component
。例如,如果执行自己的呈现并想呈现某些文本(甚至 HTML),则可以利用 JLabel
的文本呈现支持并通过此方法直接绘制它,而不会将标签添加到可见包含层次结构中。
此方法利用 CellRendererPane
处理实际的绘制,只有使用了用于呈现的组件时才建议使用此方法。如果利用多个组件处理呈现,则就像 JTable
所做的一样,那么可直接使用 CellRendererPane
。否则,如下所述,每个 Component
可以以 CellRendererPane
结尾。
如果 c
的父组件不是 CellRendererPane
,则创建一个新的 CellRendererPane
,将 c
添加到其中,并将 CellRendererPane
添加到 p
。如果 c
的父组件是 CellRendererPane
,并且 CellRendererPane
的父级不是 p
,则将它添加到 p
。
该组件应该从 JComponent
继承或者是另一种轻量级组件。轻量级组件是一个其 "lightweight" 属性(由该 Component
isLightweight
方法返回)为 true 的组件。如果该 Component 不是轻量级的,则可能发生以下糟糕的事情:崩溃、异常、绘制问题……
g
- 要在其上绘制的 Graphics
对象c
- 要绘制的 Component
p
- 该中间 Container
x
- 指定要在其中绘制的区域左侧的 int 值,以像素为单位,通过图形环境的左边缘测量y
- 指定要在其中绘制的区域顶部的 int 值,以像素为单位,通过图形环境的顶部边缘测量w
- 指定要在其中绘制的区域宽度的 int 值,以像素为单位h
- 指定要在其中绘制的区域高度的 int 值,以像素为单位CellRendererPane
,
Component.isLightweight()
1 2 3 4 |
|
Graphics
上绘制组件。这是 paintComponent(Graphics,Component,Container,int,int,int,int)
的一个覆盖方法。有关更多信息,请参阅它。
g
- 要在其上绘制的 Graphics
对象c
- 要绘制的 Component
p
- 该中间 Container
r
- 要在其中绘制的 Rectangle
paintComponent(Graphics,Component,Container,int,int,int,int)
,
CellRendererPane
1 |
|
updateUI()
-- 也就是说,通过当前外观初始化其 UI 属性。
1 |
|
invokeLater
调用将事件指派线程上的 Runnable
对象 doHelloWorld
加入队列,然后输出一条信息。
1 2 3 4 5 6 7 8 |
|
有关此方法的其他文档和示例,请参阅 The Java Tutorial 中的 How to Use Threads 一节。
从 1.3 版本开始,此方法只覆盖了 java.awt.EventQueue.invokeLater()
。
与 Swing 的其余部分不同,可从任一线程中调用此方法。
invokeAndWait(java.lang.Runnable)
1 2 3 |
|
doRun.run()
在 AWT 事件指派线程上同步执行。在所有挂起的 AWT 事件被处理完(然后)返回 doRun.run()
之前,此调用将处于阻塞状态。此方法应该在应用程序线程需要更新该 GUI 时使用。而不应该从 EventDispatchThread
中调用此方法。下面是一个创建新应用程序线程的示例,该应用线程使用 invokeAndWait
从事件指派线程输出一个字符串,完成后再从应用程序线程输出一个字符串。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
Runnable.run
方法抛出一个未捕获的异常(在事件指派线程上),则它将被作为一个 InvocationTargetException
(在调用者的线程上)捕获并重新抛出。
有关此方法的更多文档和示例,请参阅 The Java Tutorial 中的 How to Use Threads 一节。
从 1.3 版本开始,此方法只覆盖了 java.awt.EventQueue.invokeAndWait()
。
InterruptedException
- 如果等待事件指派线程执完成执行 doRun.run()
时被中断
InvocationTargetException
- 如果在运行 doRun
时抛出异常invokeLater(java.lang.Runnable)
1 |
|
从 1.3 版本开始,此方法只覆盖了 java.awt.EventQueue.isDispatchThread()
。
1 |
|
注:从 Java 2 平台 v1.3 开始,建议开发人员调用 Component.AccessibleAWTComponent.getAccessibleIndexInParent(),而不是使用此方法。
1 2 |
|
Point
处包含的 Accessible
子对象。否则返回 null
。
Accessible
(如果存在);否则返回 null
1 |
|
注:从 Java 2 平台 v1.3 开始,建议开发人员调用 Component.AccessibleAWTComponent.getAccessibleIndexInParent(),而不是使用此方法。
AccessibleState
1 |
|
注:从 Java 2 平台 v1.3 开始,建议开发人员调用 Component.AccessibleAWTComponent.getAccessibleIndexInParent(),而不是使用此方法。
1 2 |
|
注:从 Java 2 平台 v1.3 开始,建议开发人员调用 Component.AccessibleAWTComponent.getAccessibleIndexInParent(),而不是使用此方法。
i
- 从零开始的子对象索引
1 2 |
|
KeyboardFocusManager.getFocusOwner()
取代。
Component
的子 Component
(如果有)。
c
- 要搜索焦点所有者的 Component
层次结构的根
comp
或 comp
的后代,则返回 null
KeyboardFocusManager.getFocusOwner()
1 |
|
null
。1 |
|
1 |
|
event
关联的 Component
的键绑定。此方法仅当 event.getComponent()
不是从 JComponent
继承的,或不从 JComponent
子类中调用 super.processKeyEvent
时才有用。JComponent
自动处理其 processKeyEvent
方法中的绑定,因此一般情况下不需要直接调用此方法。
event
- 用于标识哪些绑定要处理以及哪个组件有焦点的 KeyEvent。
1 2 3 4 5 |
|
action
(且为非 null
),则调用 action
上的 actionPerformed
。ActionEvent 的命令由以下情况确定:
registerKeyboardAction
注册的,则传入命令字符串(如果传入 null
,则使用 null
)。
null
。
getKeyChar
返回 KeyEvent.CHAR_UNDEFINED。
action
为非 null
且 actionPerformed 是在其上调用的,则将返回 true。
1 2 3 |
|
component
的 UI InputMap 更改为 uiInputMap
的便捷方法。如果 uiInputMap
为 null
,则将移除以前安装的任何 UI InputMap。
1 2 |
|
component
的 UI ActionMap 更改为 uiActionMap
的便捷方法。如果 uiActionMap
为 null
,则将移除以前安装的任何 UI ActionMap。
1 2 |
|
component
中的条件 condition
的 UI 提供的 InputMap。
如果该 UI 未安装指定类型的 InputMap,则将返回 null
。
1 |
|
component
中提供的 ActionMap。
如果该 UI 未安装 ActionMap,则将返回 null
。
1 2 |
|
r
中,然后返回 r
。该位置和大小指定组件的边界,进行调整以使其不包括边框区域(即 insets)。此方法对实现绘制代码的类很有用。
c
- 相关的 JComponent;如果为 null
,则此方法返回 null
r
- 要修改的 Rectangle 实例;可以为 null
null
,则返回 null
;否则返回传入的矩形(如果为非 null
),或一个指定位置和大小信息的新矩形
|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
上一个类 下一个类 | 框架 无框架 | |||||||||
摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 |
版权所有 2004 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。