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| 修飾子と型 | メソッドと説明 |
|---|---|
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)
新しい矩形を割り当てずに、2つの矩形の共通部分を計算するのに便利です。
|
static int |
computeStringWidth(FontMetrics fm, String str)
指定されたメトリックス(サイズ)を持つフォントを使用して文字列の幅を計算します。
|
static Rectangle |
computeUnion(int x, int y, int width, int height, Rectangle dest)
新しい矩形を割り当てないで2つの矩形の結合部分を算出する簡易メソッドです。
|
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番目のAccessible子を返します。
|
static int |
getAccessibleChildrenCount(Component c)
オブジェクト内のAccessible子の数を返します。
|
static int |
getAccessibleIndexInParent(Component c)
このオブジェクトの、そのAccessible親でのインデックスを取得します。
|
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の、もっとも深い可視の子孫Componentを返します。 |
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)
UIが
componentのconditionに指定したInputMapを返します。 |
static Container |
getUnwrappedParent(Component component)
JLayerのインスタンスではない、componentの最初の祖先を返します。 |
static Component |
getUnwrappedView(JViewport viewport)
JLayerのインスタンスではない、JViewportの最初の子孫を返します。 |
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)
単純なLook & Feelの変更で、ツリー内の各ノードに
updateUI()処理を行うこと、つまり現在のLook & FeelでそのUIプロパティを初期化することを要求します。 |
static Window |
windowForComponent(Component c)
cの最初のWindow 祖先か、またはcがWindowの内部に含まれていない場合はnullを返します。 |
public static final boolean isRectangleContainingRectangle(Rectangle a, Rectangle b)
aがbを含む場合にtrueを返します。public static Rectangle getLocalBounds(Component aComponent)
aComponentの矩形(0,0,bounds.width,bounds.height)を返します。public static Window getWindowAncestor(Component c)
cの最初のWindow 祖先か、またはcがWindowの内部に含まれていない場合はnullを返します。c - Window祖先を取得するComponent。cの最初のWindow 祖先か、cがWindowの内部に含まれていない場合はnull。public static Point convertPoint(Component source, Point aPoint, Component destination)
source座標系内のaPointを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)
source座標系内のポイント(x,y)を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)
source座標系内の矩形aRectangleをdestination座標系に変換します。sourceがnullの場合、aRectangleはdestinationのルート・コンポーネント座標系にあるものと想定されます。destinationがnullの場合、aRectangleはsourceのルート・コンポーネント座標系に変換されます。sourceとdestinationがいずれもnullの場合は、変換せずにaRectangleを返します。public static Container getAncestorOfClass(Class<?> c, Component comp)
compの上位を検索するための簡易メソッドであり、見つかったクラスcの最初のオブジェクトを返します。cクラスが見つからない場合はnullを返します。public static Container getAncestorNamed(String name, Component comp)
compの上位を検索するための簡易メソッドであり、見つかったnameの最初のオブジェクトを返します。nameが見つからない場合はnullを返します。public static Component getDeepestComponentAt(Component parent, int x, int y)
x、yを含むparentの、もっとも深い可視の子孫Componentを返します。parentが指定された位置を内包していない場合は、nullが返されます。parentがコンテナではない場合、あるいはparentの可視の子孫がどれも指定された位置を内包していない場合は、parentが返されます。parent - 検索を開始するルート・コンポーネントx - xターゲット位置y - yターゲット位置public static MouseEvent convertMouseEvent(Component source, MouseEvent sourceEvent, Component destination)
sourceEventと同様のMouseEventを返します(そのxとyメンバーがdestinationの座標体系に変換済みの場合を除く)。sourceがnullの場合、sourceEventのxとyメンバーはdestinationのルート・コンポーネント座標系に入るものと想定されます。destinationがnullの場合、返されたMouseEventはsourceの座標系に入ります。sourceEventは変更されません。新しいイベントが返されます。destinationがnull以外の場合、返されたイベントのsourceフィールドはdestinationに設定されます。translateMouseEvent()メソッドを使用すると、sourceを変更せずに、コンポーネントのマウス・イベントを別のコンポーネントに変換できます。public static void convertPointToScreen(Point p, Component c)
p - 新しい座標系に変換されるPointオブジェクトc - Componentオブジェクトpublic static void convertPointFromScreen(Point p, Component c)
p - 新しい座標系に変換されるPointオブジェクトc - Componentオブジェクトpublic static Window windowForComponent(Component c)
cの最初のWindow 祖先か、またはcがWindowの内部に含まれていない場合はnullを返します。
注: このメソッドの機能は、getWindowAncestorと同じです。
c - Window祖先を取得するComponent。cの最初のWindow 祖先か、cがWindowの内部に含まれていない場合はnull。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 - 2番目の矩形destpublic static Rectangle computeUnion(int x, int y, int width, int height, Rectangle dest)
x - 最初の矩形のx座標y - 最初の矩形のy座標width - 最初の矩形の幅height - 最初の矩形の高さdest - 2番目の矩形の座標。2つの矩形の和集合がこの矩形で返されるdest Rectanglepublic static Rectangle[] computeDifference(Rectangle rectA, Rectangle rectB)
rectBとオーバーラップしないrectA内の領域を表す矩形の配列を返すのに便利です。2つの矩形がオーバーラップしない場合は、空の配列を返します。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 - 計算に使用するFontMetricsオブジェクトstr - 計算対象のStringpublic 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で、コンポーネントをペイントします。このメソッドは、主に可視の包含関係の階層には含まれていないが描画に使用されるComponentを描画するために使用されます。たとえば、描画時にテキストやHTMLを描画する場合は、JLabelのテキスト描画機能を利用して、このメソッドで直接ペイントできます。このとき、ラベルを可視の包含関係の階層に追加する必要はありません。
このメソッドは、CellRendererPaneを利用して、実際のペイントを処理します。描画に単一のコンポーネントを使用する場合にのみ使用するようにしてください。JTableのように複数のコンポーネントを利用して描画を行う場合は、CellRendererPaneを直接使用してください。そうでない場合は、次に示すように、ComponentごとにCellRendererPaneを呼び出します。
cの親がCellRendererPaneでない場合、新しいCellRendererPaneが作成され、それにcが追加されます。また、CellRendererPaneがpに追加されます。cの親がCellRendererPaneであり、CellRendererPaneの親がpでない場合、それがpに追加されます。
コンポーネントは、JComponentの子孫であるか、別の種類の軽量コンポーネントであることが必要です。軽量コンポーネントとは、Component isLightweightメソッドによって返される「軽量」プロパティがtrueであるようなコンポーネントです。Componentが軽量でない場合は、クラッシュ、例外、ペイント関連の問題など、不正な事態が発生することがあります。
g - 描画先のGraphicsオブジェクトc - 描画対象のComponentp - 中間Containerx - 描画領域の左端を表す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 - 描画対象のComponentp - 中間Containerr - 描画対象のRectanglepaintComponent(Graphics,Component,Container,int,int,int,int), CellRendererPanepublic static void updateComponentTreeUI(Component c)
updateUI()処理を行うこと、つまり現在のLook & FeelでそのUIプロパティを初期化することを要求します。public static void invokeLater(Runnable doRun)
invokeLater呼出しはイベント・ディスパッチ・スレッドにRunnableオブジェクトのdoHelloWorldのキューを呼び出してから、メッセージを出力します。
Runnable doHelloWorld = new Runnable() {
public void run() {
System.out.println("Hello World on " + Thread.currentThread());
}
};
SwingUtilities.invokeLater(doHelloWorld);
System.out.println("This might well be displayed before the other message.");
invokeLaterがイベント・ディスパッチ・スレッド、たとえばJButtonのActionListenerから呼び出された場合、doRun.run()は保留中のすべてのイベントが処理されるまで実行が延期されます。ただし、doRun.run()がキャッチされない例外をスローする場合は、イベント・ディスパッチ・スレッド(現在のスレッドではない)が状態を元に戻します。
このメソッドの追加のドキュメントと例は、「Concurrency in Swing」を参照してください。
JDK Version 1.3以降、このメソッドはjava.awt.EventQueue.invokeLater()を呼び出すだけです。
このメソッドは、ほかのSwingのメソッドとは異なり、どのスレッドからでも呼び出せます。
public static void invokeAndWait(Runnable doRun) throws InterruptedException, InvocationTargetException
doRun.run()を、AWTイベント・ディスパッチ・スレッドで非同期的に実行させます。この呼び出しは、保留中のすべてのAWTイベントが処理されるまでブロックされ、次にdoRun.run()が復帰します。このメソッドは、アプリケーション・スレッドがGUIを更新する必要があるときに使用されます。イベント・ディスパッチ・スレッドから呼び出してはいけません。新しいアプリケーション・スレッドを生成する例を、次に示します。この例では、アプリケーション・スレッドはinvokeAndWaitを使用してイベント・ディスパッチ・スレッドから文字列を出力し、その後、アプリケーション・スレッドから文字列を出力します。
final Runnable doHelloWorld = new Runnable() {
public void run() {
System.out.println("Hello World on " + Thread.currentThread());
}
};
Thread appThread = new Thread() {
public void run() {
try {
SwingUtilities.invokeAndWait(doHelloWorld);
}
catch (Exception e) {
e.printStackTrace();
}
System.out.println("Finished on " + Thread.currentThread());
}
};
appThread.start();
Runnable.runメソッドがキャッチされない例外をイベント・ディスパッチ元スレッドでスローする場合は、その例外は呼出し側のスレッドで、InvocationTargetExceptionとしてキャッチされて再スローされます。
このメソッドの追加のドキュメントと例は、「Concurrency in Swing」を参照してください。
JDK Version 1.3以降、このメソッドはjava.awt.EventQueue.invokeAndWait()を呼び出すだけです。
InterruptedException - イベント・ディスパッチ・スレッドがdoRun.run()の実行を終えるのを待機する間に割込みを受けた場合InvocationTargetException - doRunの実行中に例外がスローされる場合invokeLater(java.lang.Runnable)public static boolean isEventDispatchThread()
JDK Version 1.3以降、このメソッドはjava.awt.EventQueue.isDispatchThread()を呼び出すだけです。
public static int getAccessibleIndexInParent(Component c)
注: Java 2プラットフォームv1.3以降、開発者はこのメソッドを使用する代わりに、Component.AccessibleAWTComponent.getAccessibleIndexInParent()を呼び出すことをお勧めします。
public static Accessible getAccessibleAt(Component c, Point p)
Pointに含まれているAccessible子が存在する場合は、それを返します。それ以外の場合はnullを返します。Accessible。そうでない場合はnullpublic static AccessibleStateSet getAccessibleStateSet(Component c)
注: Java 2プラットフォームv1.3以降、開発者はこのメソッドを使用する代わりに、Component.AccessibleAWTComponent.getAccessibleIndexInParent()を呼び出すことをお勧めします。
AccessibleStatepublic static int getAccessibleChildrenCount(Component c)
注: Java 2プラットフォームv1.3以降、開発者はこのメソッドを使用する代わりに、Component.AccessibleAWTComponent.getAccessibleIndexInParent()を呼び出すことをお勧めします。
public static Accessible getAccessibleChild(Component c, int i)
注: Java 2プラットフォームv1.3以降、開発者はこのメソッドを使用する代わりに、Component.AccessibleAWTComponent.getAccessibleIndexInParent()を呼び出すことをお勧めします。
i - 子のゼロから始まるインデックス@Deprecated public static Component findFocusOwner(Component c)
KeyboardFocusManager.getFocusOwner()に置き換えられています。Componentの子Componentを返します(存在する場合)。c - フォーカス所有者を検索するときのComponent階層のルートcompでない場合、またはフォーカス所有者がcompの子孫である場合はnullKeyboardFocusManager.getFocusOwner()public static JRootPane getRootPane(Component c)
null。public static Component getRoot(Component c)
public static boolean processKeyBindings(KeyEvent event)
eventに関連付けられたComponentのキー・バインディングを処理します。このメソッドが便利なのは、event.getComponent()がJComponentの下位である場合、またはJComponentサブクラス内からsuper.processKeyEventを呼び出していない場合だけです。JComponentは、自身のprocessKeyEventメソッド内から自動的にバインディングを処理するため、このメソッドを直接呼び出すことが必要となる場合はほとんどありません。event - フォーカスを持つComponentおよび処理対象のバインディングを指定するKeyEvent。public static boolean notifyAction(Action action, KeyStroke ks, KeyEvent event, Object sender, int modifiers)
actionが使用可能で、かつnullでない場合、actionのactionPerformedを呼び出します。ActionEventのコマンドは次の値で指定されます。
registerKeyboardActionを使用して登録された場合は、渡されたコマンド文字列(nullが渡された場合はnull)。
nullでないかぎり、Action.ACTION_COMMAND_KEYという名前を持つAction値。
getKeyCharがKeyEvent.CHAR_UNDEFINEDを返さないかぎり、KeyEventのString値。
actionがnull以外で、actionPerformedが呼び出されると、trueを返します。public static void replaceUIInputMap(JComponent component, int type, InputMap uiInputMap)
componentのUI InputMapをuiInputMapに変更する簡易メソッドです。uiInputMapがnullの場合、このメソッドは以前にインストールされたUI InputMapを削除します。public static void replaceUIActionMap(JComponent component, ActionMap uiActionMap)
componentのUI ActionMapをuiActionMapに変更する簡易メソッドです。uiActionMapがnullの場合、このメソッドは以前にインストールされたUI ActionMapを削除します。public static InputMap getUIInputMap(JComponent component, int condition)
componentのconditionに指定したInputMapを返します。
このメソッドは、UIが指定された型のInputMapをインストールしていない場合にnullを返します。
public static ActionMap getUIActionMap(JComponent component)
componentに指定したActionMapを返します。
このメソッドは、UIが指定された型のActionMapをインストールしていない場合にnullを返します。
public static Rectangle calculateInnerArea(JComponent c, Rectangle r)
rに格納し、rを返します。位置とサイズは、コンポーネントの境界を示し、ボーダー領域を含まないように調整されます(イン・セット)。このメソッドは、ペイントするコードを実装するクラスに対して便利です。c - 対象のJComponent。このメソッドがnullを返す場合はnullr - 変更されるRectangleのインスタンス。nullnullの場合はnull。そうでない場合は渡された矩形(null以外の場合)、または位置およびサイズ情報を指定する新しい矩形public static Container getUnwrappedParent(Component component)
JLayerのインスタンスではない、componentの最初の祖先を返します。component - JLayerインスタンスではない、最初の祖先を取得するComponent。JLayerのインスタンスではない、componentの最初の祖先。そのような祖先が見つからない場合は、nullを返します。NullPointerException - componentがnullである場合JLayerpublic static Component getUnwrappedView(JViewport viewport)
JLayerのインスタンスではない、JViewportの最初の子孫を返します。そのような子孫が見つかった場合は、nullを返します。viewportのビュー・コンポーネントがJLayerでない場合、このメソッドはJViewport.getView()と同じであり、それ以外の場合は、JLayer.getView()が降順のすべてのJLayerで再帰的に呼び出されます。viewport - JLayerインスタンスではない、最初の子孫を取得するJViewport。JLayerのインスタンスではない、JViewportの最初の子孫。そのような子孫が見つかった場合は、nullを返します。NullPointerException - viewportがnullである場合JViewport.getView(), JLayer バグまたは機能を送信
詳細なAPIリファレンスおよび開発者ドキュメントについては、Java SEのドキュメントを参照してください。そのドキュメントには、概念的な概要、用語の定義、回避方法、有効なコード例などの、開発者を対象にしたより詳細な説明が含まれています。
Copyright© 1993, 2014, Oracle and/or its affiliates. All rights reserved.