public class SwingUtilities extends Object implements SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST| Modifier and Type | Method and Description |
|---|---|
static Rectangle |
calculateInnerArea(JComponent c, Rectangle r)
商店的位置和大小的内画区指定的组件在
r返回
r。
|
static Rectangle[] |
computeDifference(Rectangle rectA, Rectangle rectB)
方便返回矩形代表区域内
rectA不重叠
rectB数组。
|
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除了其X和Y的成员已经转换为
destination的坐标系统。
|
static Point |
convertPoint(Component source, int x, int y, Component destination)
将点
(x,y)在
source坐标系统
destination坐标系统。
|
static Point |
convertPoint(Component source, Point aPoint, Component destination)
将一个
aPoint在
source坐标系统的坐标系统
destination。
|
static void |
convertPointFromScreen(Point p, Component c)
将一个点从屏幕坐标转换成一个组件的坐标系统
|
static void |
convertPointToScreen(Point p, Component c)
将一个点从一个组件的坐标系统转换为屏幕坐标。
|
static Rectangle |
convertRectangle(Component source, Rectangle aRectangle, Component destination)
将矩形
aRectangle在
source坐标系统的坐标系统
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(类<?> c, Component comp)
方便的搜索方法在构件层次
comp返回找到的第一个对象类
c。
|
static Component |
getDeepestComponentAt(Component parent, int x, int y)
返回深可见后裔组成的
parent包含位置
x,
y。
|
static Rectangle |
getLocalBounds(Component aComponent)
返回的矩形(0,0,界限。宽度范围。高度)的组件
aComponent
|
static Component |
getRoot(Component c)
返回当前组件树的根组件。
|
static JRootPane |
getRootPane(Component c)
如果C是一个jrootpane后裔返回其jrootpane祖先。
|
static ActionMap |
getUIActionMap(JComponent component)
返回的
component UI组件提供的actionmap。
|
static InputMap |
getUIInputMap(JComponent component, int condition)
返回的
component条件
condition UI组件提供的inputmap。
|
static Container |
getUnwrappedParent(Component component)
返回的
component不是
JLayer实例的始祖。
|
static Component |
getUnwrappedView(JViewport viewport)
返回第一个
JViewport的后裔,是不是
JLayer实例。
|
static Window |
getWindowAncestor(Component c)
返回
c第一
Window 祖先,或
null如果
c不包含在一
Window。
|
static void |
invokeAndWait(Runnable doRun)
原因
doRun.run()是同步执行的事件派发线程。
|
static void |
invokeLater(Runnable doRun)
原因run()东岭。是异步执行的事件派发线程。
|
static boolean |
isDescendingFrom(Component a, Component b)
如果一个组件
a下降从一个组件
b返回
true
|
static boolean |
isEventDispatchThread()
如果当前线程是事件派发线程返回true。
|
static boolean |
isLeftMouseButton(MouseEvent anEvent)
如果鼠标事件指定鼠标左键,则返回真。
|
static boolean |
isMiddleMouseButton(MouseEvent anEvent)
如果鼠标事件指定鼠标中键,则返回真。
|
static boolean |
isRectangleContainingRectangle(Rectangle a, Rectangle b)
如果
a包含
b返回true
|
static boolean |
isRightMouseButton(MouseEvent anEvent)
如果鼠标事件指定鼠标右键,则返回真。
|
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)
如果在调用
actionPerformed
action
action启用(而非
null)。
|
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)
要改变用户界面actionmap为
component到
uiActionMap便利的方法。
|
static void |
replaceUIInputMap(JComponent component, int type, InputMap uiInputMap)
要改变用户界面inputmap为
component到
uiInputMap便利的方法。
|
static void |
updateComponentTreeUI(Component c)
一个头脑简单的外观和感觉的变化:问树中的每个节点
updateUI() --也就是说,以目前看初始化界面性质和感觉。
|
static Window |
windowForComponent(Component c)
返回
c第一
Window 祖先,或
null如果
c不包含在一
Window。
|
public static final boolean isRectangleContainingRectangle(Rectangle a, Rectangle b)
a包含
b
public static Rectangle getLocalBounds(Component aComponent)
aComponent
public static Window getWindowAncestor(Component c)
c第一
Window 祖先,或
null如果
c不包含在一
Window。
c -
Component得到
Window祖先。
c第一
Window 祖先,或
null如果
c不包含在一
Window。
public static Point convertPoint(Component source, Point aPoint, Component destination)
aPoint在
source坐标系统的坐标系统
destination。如果
source是
null,
aPoint被假定为在
destination的根组件的坐标系统。如果
destination是
null,
aPoint将转换为
source的根组件的坐标系统。如果
source和
destination是
null,
aPoint没有任何转换回。
public static Point convertPoint(Component source, int x, int y, Component destination)
(x,y)在
source坐标系统
destination坐标系统。如果
source是
null,
(x,y)被假定为在
destination的根组件的坐标系统。如果
destination是
null,
(x,y)将转换为
source的根组件的坐标系统。如果
source和
destination是
null,
(x,y)没有任何转换回。
public static Rectangle convertRectangle(Component source, Rectangle aRectangle, Component destination)
aRectangle在
source坐标系统的坐标系统
destination。如果
source是
null,
aRectangle被假定为在
destination的根组件的坐标系统。如果
destination是
null,
aRectangle将转换为
source的根组件的坐标系统。如果
source和
destination是
null,
aRectangle没有任何转换回。
public static Container getAncestorOfClass(类<?> c, Component comp)
comp返回找到的第一个对象类
c。可以返回
null,如果一个类
c无法找到。
public static Container getAncestorNamed(String name, Component comp)
comp和返回的第一个目标
name发现。可以返回
null,如果
name无法找到。
public static Component getDeepestComponentAt(Component parent, int x, int y)
parent包含位置
x,
y。如果
parent不包含指定的位置,然后
null返回。如果
parent不是容器,或
parent可见后代没有指定位置,
parent返回。
parent -开始搜索根组件
x - X的目标位置
y -目标定位
public static MouseEvent convertMouseEvent(Component source, MouseEvent sourceEvent, Component destination)
sourceEvent除了其X和Y的成员已经转换为
destination的坐标系统。如果
source是
null,
sourceEvent X和Y的成员被认为是为
destination的根组件的坐标系统。如果
destination是
null,返回的事件将在
source的坐标系统。
sourceEvent不会改变。返回一个新的事件。返回的事件
source字段将被设置为
destination如果目标是非
null使用translatemouseevent()法模拟鼠标事件从一个组件到另一个不改变源。
public static void convertPointToScreen(Point p, Component c)
p一点对象(转换到新的坐标系统)
c -一个组件对象
public static void convertPointFromScreen(Point p, Component c)
p一点对象(转换到新的坐标系统)
c -一个组件对象
public static Window windowForComponent(Component c)
c第一
Window 祖先,或
null如果
c不包含在一
Window。
注:此方法提供相同的功能作为getWindowAncestor。
c -
Component得到
Window祖先。
c第一
Window 祖先,或
null如果
c不包含在一
Window。
public static boolean isDescendingFrom(Component a, Component b)
a下降从一个组件
b返回
true
public static Rectangle computeIntersection(int x, int y, int width, int height, Rectangle dest)
x -第一个矩形的左上点的x坐标
y -第一个矩形的左上点的Y坐标
width -第一个矩形的宽度
height -第一个矩形的高度
dest -第二矩形
dest,修改指定的路口
public static Rectangle computeUnion(int x, int y, int width, int height, Rectangle dest)
x -第一个矩形的坐标
y -第一个矩形的坐标
width -第一个矩形的宽度
height -第一个矩形的高度
dest -第二矩形的坐标;两个矩形的联盟在这个矩形返回
dest
Rectangle
public static Rectangle[] computeDifference(Rectangle rectA, Rectangle rectB)
rectA不重叠
rectB数组。如果两个矩形不重叠,返回一个空数组
public static boolean isLeftMouseButton(MouseEvent anEvent)
anEvent -一个MouseEvent对象
public static boolean isMiddleMouseButton(MouseEvent anEvent)
anEvent -一个MouseEvent对象
public static boolean isRightMouseButton(MouseEvent anEvent)
anEvent -一个MouseEvent对象
public static int computeStringWidth(FontMetrics fm, String str)
fm -根据对象来计算
str来计算字符串
public 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)
public 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)
public static void paintComponent(Graphics g, Component c, Container p, int x, int y, int w, int h)
Graphics。这种方法主要是使
Components不为可见的层次结构的一部分存在是有用的,但用于渲染。例如,如果你正在做你自己的渲染和想渲染一些文本(或HTML),你可以利用
JLabel的文本渲染支持有油漆直接借助该方法,无需添加标签的可见的层次结构。
该方法利用CellRendererPane处理实际的画,而只是建议如果你使用一个组件的渲染。如果你使用多个组件来处理渲染,为JTable,直接使用CellRendererPane。否则,在下面的描述,你可以建立一个CellRendererPane每Component。
如果c的父母不是CellRendererPane,新CellRendererPane创建,c添加到它,和CellRendererPane加入p。如果c的母公司是一CellRendererPane和CellRendererPanes母不p,它被添加到p。
组件应该下降JComponent或是另一种轻量级组件。一个轻量级的组件是一个“轻量级”的性质(由Component isLightweight方法返回)是真的。如果组件不是轻量级的,坏的事情Map发生:崩溃,例外,绘画问题…
g -
Graphics对象绘制
c -
Component画
p -中间
Container
x指定区域的左边画,在像素的int型,从图形上下文的左边缘检测
y指定的区域画上一个int,测量从图形背景下的顶部边缘像素
w指定区域的宽度画一个int,像素
h指定区域的高度画一个int,像素
CellRendererPane,
Component.isLightweight()
public static void paintComponent(Graphics g, Component c, Container p, Rectangle r)
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
public static void updateComponentTreeUI(Component c)
updateUI() --也就是说,以目前看初始化界面性质和感觉。
public static void invokeLater(Runnable doRun)
invokeLater呼叫队列在事件分发线程对象的
Runnable
doHelloWorld然后打印一个消息。如果
运行dohelloworld =新runnable() {run() { public void系统的输入(“Hello World”+线。currentthread());}};swingutilities invokeLater(dohelloworld);系统的输入(“这可能显示在其他消息。”); invokeLater称从事件调度线程,例如,从一个JButton的功能-- run()东岭。仍将推迟到所有等待的事件已处理。注意,如果run()东岭。抛出未捕获的异常事件调度线程将放松(不是当前线程)。
这一方法附加文档和示例可以在Concurrency in Swing。
作为1.3这种方法只是一种掩护java.awt.EventQueue.invokeLater()。
与其他的摇摆不一样,这种方法可以从任何线程调用。
public static void invokeAndWait(Runnable doRun) throws InterruptedException, InvocationTargetException
doRun.run()是同步执行的事件派发线程。这叫块直到所有未决的AWT事件已处理,(然后)
doRun.run()返回。当应用程序线程需要更新用户界面时,该方法应该使用这个方法。它不应该从事件调度线程调用。这是一个创建新的应用程序的线程使用
invokeAndWait从事件调度线程打印一个字符串,然后,结束后,打印应用程序线程的字符串。
最后运行dohelloworld =新runnable() {run() { public void系统的输入(“Hello World”+线。currentthread());}};螺纹appthread =新thread() {run() { public void尝试{swingutilities invokeandwait(dohelloworld);}捕获(异常E)E. printstacktrace();}系统的输入(“”+线。currentthread()完成);}};appthread。start();注意如果
Runnable.run方法抛出未捕获的异常(在事件分发线程)捉到并,作为
InvocationTargetException,在调用者的线程。
这一方法附加文档和示例可以在Concurrency in Swing。
作为1.3这种方法只是一种掩护java.awt.EventQueue.invokeAndWait()。
InterruptedException -如果我们在等待事件调度线程执行完
doRun.run()中断
InvocationTargetException如果抛出运行时
doRun是个例外
invokeLater(java.lang.Runnable)
public static boolean isEventDispatchThread()
作为1.3这种方法只是一种掩护java.awt.EventQueue.isDispatchThread()。
public static int getAccessibleIndexInParent(Component c)
注:作为java 2平台V1.3,建议开发商调用组件。accessibleawtcomponent。而不是用这种方法getaccessibleindexinparent()。
public static Accessible getAccessibleAt(Component c, Point p)
Point的
Accessible孩子,如果存在。否则返回
null。
Accessible,如果它存在;否则
null
public static AccessibleStateSet getAccessibleStateSet(Component c)
注:作为java 2平台V1.3,建议开发商调用组件。accessibleawtcomponent。而不是用这种方法getaccessibleindexinparent()。
AccessibleState
public static int getAccessibleChildrenCount(Component c)
注:作为java 2平台V1.3,建议开发商调用组件。accessibleawtcomponent。而不是用这种方法getaccessibleindexinparent()。
public static Accessible getAccessibleChild(Component c, int i)
注:作为java 2平台V1.3,建议开发商调用组件。accessibleawtcomponent。而不是用这种方法getaccessibleindexinparent()。
i -零基础指数的孩子
@Deprecated public static Component findFocusOwner(Component c)
KeyboardFocusManager.getFocusOwner()。
Component是重点业主的孩子
Component,如果任何。
c的
Component层次搜索焦点所有者的根
null如果没有集中的所有者,或者如果焦点所有者不
comp,或后裔
comp
KeyboardFocusManager.getFocusOwner()
public static JRootPane getRootPane(Component c)
null的jrootpane。
public static boolean processKeyBindings(KeyEvent event)
event的
Component的键绑定。如果
event.getComponent()不下降
JComponent这种方法才是有用的,或者你不在你的
JComponent子类调用
super.processKeyEvent。
JComponent自动处理绑定的
processKeyEvent方法内,所以你很少需要直接调用该方法。
event KeyEvent用来确定绑定的过程,以及哪些组件具有焦点。
public static boolean notifyAction(Action action, KeyStroke ks, KeyEvent event, Object sender, int modifiers)
actionPerformed
action
action启用(而非
null)。为ActionEvent命令是确定的:如果
action
registerKeyboardAction注册,然后命令传入的字符串(null将如果null是通过使用)。null。getKeyChar返回。char_undefined ..null和actionPerformed返回调用它。
public static void replaceUIInputMap(JComponent component, int type, InputMap uiInputMap)
component到
uiInputMap便利的方法。如果
uiInputMap是
null,这消除了任何以前安装的UI inputmap。
public static void replaceUIActionMap(JComponent component, ActionMap uiActionMap)
component到
uiActionMap便利的方法。如果
uiActionMap是
null,这消除了任何以前安装的UI actionmap。
public static InputMap getUIInputMap(JComponent component, int condition)
component条件
condition UI提供
这会如果用户没有安装inputmap指定类型的返回null。
public static ActionMap getUIActionMap(JComponent component)
component UI组件提供的actionmap。
这会如果用户没有安装actionmap返回null。
public static Rectangle calculateInnerArea(JComponent c, Rectangle r)
r
r并返回指定组件的内部绘画面积的大小,位置,位置和大小指定组件的范围,调整为不包括边境地区(插图)。此方法对于实现绘图代码的类是有用的。
c -问题的组件;如果
null,此方法返回
null
r -矩形实例进行修改;可以
null
null如果组件是
null;否则,返回传入的矩形(如果非
null)或一个新的矩形指定位置信息和尺寸
public static Container getUnwrappedParent(Component component)
component不是
JLayer实例的始祖。
component -
Component得到的始祖,这是一个不
JLayer实例。
component不是
JLayer实例的始祖。如果这样的祖先无法找到,
null返回。
null
component
NullPointerException
JLayer
public static Component getUnwrappedView(JViewport viewport)
JViewport的后裔,是不是
JLayer实例。如果这样的后代不被发现,
null返回。如果
viewport视图组件不是
JLayer,此方法等效于
JViewport.getView()否则
JLayer.getView()将递归调用所有降
JLayers。
viewport -
JViewport获得的第一个后代,这不是一个
JLayer实例。
JViewport的后裔,是不是
JLayer实例。如果这样的后代不被发现,
null返回。
null
viewport
NullPointerException
JViewport.getView(),
JLayer
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.