Java プラットフォーム 1.2

javax.swing
クラス SwingUtilities

java.lang.Object
  |
  +--javax.swing.SwingUtilities

public class SwingUtilities
extends Object
implements SwingConstants

Swing のユーティリティメソッドのコレクションです。


メソッドの概要
static Rectangle[] computeDifference(Rectangle rectA, Rectangle rectB)
          rectB とオーバーラップしない rectA 内の領域を表現する矩形の配列を返すために使われます。
static Rectangle computeIntersection(int x, int y, int width, int height, Rectangle dest)
          新しい矩形 dest を割り当てずに、2 つの矩形の共通部分を計算するのに便利です。
static int computeStringWidth(FontMetrics fm, String str)
          指定されたメトリックス (サイズ) を持つフォントを使って文字列の幅を計算します。
static Rectangle computeUnion(int x, int y, int width, int height, Rectangle dest)
          新しい矩形 dest を割り当てずに、2 つの矩形の和集合を計算するのに便利です。
static MouseEvent convertMouseEvent(Component source, MouseEvent sourceEvent, Component destination)
          その x と y メンバが destination の座標系に変換済みの場合を除いて、sourceEvent と同じような MouseEvent を返します。
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 座標系の aPointdestination 座標系に変換します。
static void convertPointFromScreen(Point p, Component c)
          ポイントを画面座標からコンポーネントの座標系に変換します。
static void convertPointToScreen(Point p, Component c)
          ポイントをコンポーネントの座標系から画面座標に変換します。
static Rectangle convertRectangle(Component source, Rectangle aRectangle, Component destination)
          source 座標系の aRectangledestination 座標系に変換します。
static Component findFocusOwner(Component c)
          フォーカスを持つ子コンポーネントがある場合はそれを返します。
static Accessible getAccessibleAt(Component c, Point p)
          ローカル座標の Point にユーザ補助機能を実装する子が保持されている場合はそれを返します。
static Accessible getAccessibleChild(Component c, int i)
          オブジェクトのユーザ補助機能を実装する i 番目の子を返します。
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)
          位置 xy を内包する 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 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)
          ab を保持する場合に 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 void paintComponent(Graphics g, Component c, Container p, int x, int y, int w, int h)
          矩形の左上隅およびサイズを指定して、指定された矩形内の任意のグラフィックス g でコンポーネント c をペイントします。
static void paintComponent(Graphics g, Component c, Container p, Rectangle r)
          Rectangle オブジェクトを指定して、指定された矩形内の任意のグラフィックス g でコンポーネント c をペイントします。
static void updateComponentTreeUI(Component c)
          単純な Look & Feel の変更で、ツリー内の各ノードに updateUI() 処理を行うこと、つまり現在の Look & Feel でその UI プロパティを初期化することを要求します。
static Window windowForComponent(Component aComponent)
          aComponent のウィンドウを返します。
 
クラス java.lang.Object から継承したメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

メソッドの詳細

isRectangleContainingRectangle

public static final boolean isRectangleContainingRectangle(Rectangle a,
                                                           Rectangle b)
ab を保持する場合に true を返します。

getLocalBounds

public static Rectangle getLocalBounds(Component aComponent)
aComponent コンポーネントの矩形 (0,0,bounds.width,bounds.height) を返します。

convertPoint

public static Point convertPoint(Component source,
                                 Point aPoint,
                                 Component destination)
source 座標系の aPointdestination 座標系に変換します。source が null の場合、aPointdestination のルートコンポーネント座標系にあるものと想定されます。destination が null の場合、aPointsource のルートコンポーネント座標系に変換されます。sourcedestination がどちらとも null の場合、変換しないで aPoint を返します。

convertPoint

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 のルートコンポーネント座標系に変換されます。sourcedestination がどちらとも null の場合、変換しないで (x,y) を返します。

convertRectangle

public static Rectangle convertRectangle(Component source,
                                         Rectangle aRectangle,
                                         Component destination)
source 座標系の aRectangledestination 座標系に変換します。source が null の場合、aRectangledestination のルートコンポーネント座標系にあるものと想定されます。destination が null の場合、aRectanglesource のルートコンポーネント座標系に変換されます。sourcedestination がどちらとも null の場合、変換しないで aRectangle を返します。

getAncestorOfClass

public static Container getAncestorOfClass(Class c,
                                           Component comp)
コンポーネント階層の上位の comp を検索するための簡易メソッドであり、見つかった c クラスの最初のオブジェクトを返します。c クラスが見つからない場合は null を返します。

getAncestorNamed

public static Container getAncestorNamed(String name,
                                         Component comp)
コンポーネント階層の上記の comp を検索するための簡易メソッドであり、見つかった name の最初のオブジェクトを返します。name が見つからない場合は null を返します。

getDeepestComponentAt

public static Component getDeepestComponentAt(Component parent,
                                              int x,
                                              int y)
位置 xy を内包する parent を親として持つ、最下位の可視 Component を返します。parent が指定された位置を内包していない場合は、null が返されます。parent がコンテナではない場合、あるいは parent の可視の子がどれも指定された位置を内包していない場合は、parent が返されます。
パラメータ:
parent - 検索を開始するルートコンポーネント
x - x ターゲット位置
y - y ターゲット位置

convertMouseEvent

public static MouseEvent convertMouseEvent(Component source,
                                           MouseEvent sourceEvent,
                                           Component destination)
その x と y メンバが destination の座標系に変換済みの場合を除いて、sourceEvent と同じような MouseEvent を返します。source が null の場合、sourceEvent の x と y メンバは destination のルートコンポーネント座標系に入るものと想定されます。destinationnull の場合、返された MouseEvent は source の座標系に入ります。sourceEvent は変更されません。新しいイベントが返されます。destination が null 以外の場合、返されたイベントの source フィールドは destination に設定されます。translateMouseEvent() メソッドを使うと、source を変更しないであるコンポーネントのマウスイベントを別のコンポーネントに変換できます。

convertPointToScreen

public static void convertPointToScreen(Point p,
                                        Component c)
ポイントをコンポーネントの座標系から画面座標に変換します。
パラメータ:
p - Point オブジェクト (新しい座標系に変換される)
c - Component オブジェクト

convertPointFromScreen

public static void convertPointFromScreen(Point p,
                                          Component c)
ポイントを画面座標からコンポーネントの座標系に変換します。
パラメータ:
p - Point オブジェクト (新しい座標系に変換される)
c - Component オブジェクト

windowForComponent

public static Window windowForComponent(Component aComponent)
aComponent のウィンドウを返します。

isDescendingFrom

public static boolean isDescendingFrom(Component a,
                                       Component b)
コンポーネント a がコンポーネント b から派生する場合に true を返します。

computeIntersection

public static Rectangle computeIntersection(int x,
                                            int y,
                                            int width,
                                            int height,
                                            Rectangle dest)
新しい矩形 dest を割り当てずに、2 つの矩形の共通部分を計算するのに便利です。

computeUnion

public static Rectangle computeUnion(int x,
                                     int y,
                                     int width,
                                     int height,
                                     Rectangle dest)
新しい矩形 dest を割り当てずに、2 つの矩形の和集合を計算するのに便利です。

computeDifference

public static Rectangle[] computeDifference(Rectangle rectA,
                                            Rectangle rectB)
rectB とオーバーラップしない rectA 内の領域を表現する矩形の配列を返すために使われます。2 つの矩形がオーバーラップしない場合は、空の配列を返します。

isLeftMouseButton

public static boolean isLeftMouseButton(MouseEvent anEvent)
マウスイベントが左マウスボタンを示す場合に true を返します。
パラメータ:
anEvent - MouseEvent オブジェクト
戻り値:
左マウスボタンがアクティブだった場合は true

isMiddleMouseButton

public static boolean isMiddleMouseButton(MouseEvent anEvent)
マウスイベントが中央のマウスボタンを示す場合に true を返します。
パラメータ:
anEvent - MouseEvent オブジェクト
戻り値:
中央のマウスボタンがアクティブだった場合は true

isRightMouseButton

public static boolean isRightMouseButton(MouseEvent anEvent)
マウスイベントが右マウスボタンを示す場合に true を返します。
パラメータ:
anEvent - MouseEvent オブジェクト
戻り値:
右マウスボタンがアクティブだった場合は true

computeStringWidth

public static int computeStringWidth(FontMetrics fm,
                                     String str)
指定されたメトリックス (サイズ) を持つフォントを使って文字列の幅を計算します。
パラメータ:
fm - 計算に使う FontMetrics オブジェクト
str - 計算対象の String
戻り値:
文字列の幅が格納されている int 値

layoutCompoundLabel

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)
アイコンの起点位置、テキストのベースラインの起点位置、および可能であればクリップしたバージョンの複合ラベル文字列を計算して返します。各位置は viewR の矩形を基準に計算されます。JComponent の方向 (LEADING または TRAILING) も考慮され、LEFT 値または RIGHT 値に変換されます。

layoutCompoundLabel

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)
アイコンの起点位置、テキストのベースラインの起点位置、および可能であればクリップしたバージョンの複合ラベル文字列を計算して返します。各位置は viewR の矩形を基準に計算されます。この layoutCompoundLabel() は、horizontalTextPosition (デフォルトは RIGHT) および horizontalAlignmentdoes (デフォルトは CENTER) の LEADING 値および TRAILING 値を処理できません。代わりに、ほかのバージョンの layoutCompoundLabel() を使ってください。

paintComponent

public static void paintComponent(Graphics g,
                                  Component c,
                                  Container p,
                                  int x,
                                  int y,
                                  int w,
                                  int h)
矩形の左上隅およびサイズを指定して、指定された矩形内の任意のグラフィックス g でコンポーネント c をペイントします。コンポーネントは、c.validate() 呼び出しと c.repaint() 呼び出しがツリーに伝播しないようにするプライベートコンテナ (その親が p になる) を親に設定します。この中間コンテナには、これ以外の効果はありません。
パラメータ:
g - 描画先の Graphics オブジェクト
c - 描画対象の Component
p - 中間コンテナ
x - 描画領域の左端を表す int 値 (ピクセル単位)。グラフィックスコンテキストの左端を基準とする
y - 描画領域の上端を表す int 値 (ピクセル単位)。グラフィックスコンテキストの上端を基準とする
w - 描画領域の幅を表す int 値 (ピクセル単位)
h - 描画領域の高さを表す int 値 (ピクセル単位)

paintComponent

public static void paintComponent(Graphics g,
                                  Component c,
                                  Container p,
                                  Rectangle r)
Rectangle オブジェクトを指定して、指定された矩形内の任意のグラフィックス g でコンポーネント c をペイントします。コンポーネントは、c.validate() 呼び出しと c.repaint() 呼び出しがツリーに伝播しないようにするプライベートコンテナ (その親が p になる) を再度生み出します。この中間コンテナには、これ以外の効果はありません。
パラメータ:
g - 描画先の Graphics オブジェクト
c - 描画対象の Component
p - 中間コンテナ
r - 描画先の Rectangle

updateComponentTreeUI

public static void updateComponentTreeUI(Component c)
単純な Look & Feel の変更で、ツリー内の各ノードに updateUI() 処理を行うこと、つまり現在の Look & Feel でその UI プロパティを初期化することを要求します。

invokeLater

public static void invokeLater(Runnable doRun)
doRun.run() を、AWT イベントディスパッチ元イベントで非同期的に実行させます。これは、保留中のすべての AWT イベントが処理されたあとに発生します。このメソッドは、アプリケーションスレッドが GUI を更新する必要があるときに使用されます。次の例では、invokeAndWait() 呼び出しはイベントディスパッチ元スレッドの doHelloWorld Runnable のキューを作ってから、メッセージを出力します。
 Runnable doHelloWorld = new Runnable() {
     public void run() {
         System.out.println("Hello World on " + Thread.currentThread());
     }
 };

 SwingUtilities.invokeAndWait(doHelloWorld);
 System.out.println("Waiting ... ");
 
invokeAndWait がイベントディスパッチ元スレッド、たとえば JButtons ActionListener から呼び出された場合、doRun.run() は保留中のすべてのイベントが処理されるまで実行を延期されます。ただし、doRun.run() がキャッチされない例外をスローする場合はイベントディスパッチ元スレッド (現在のスレッドではない) が状態を元に戻すので、注意してください。

このメソッドの追加のドキュメントと例については、このページを参照してください。

関連項目:
invokeAndWait(java.lang.Runnable)

invokeAndWait

public static void invokeAndWait(Runnable doRun)
                          throws InterruptedException,
                                 InvocationTargetException
doRun.run() を、AWT イベントディスパッチ元イベントで非同期的に実行させます。これは、保留中のすべての AWT イベントが処理されるまでブロックでき、次に doRun.run() が復帰します。このメソッドは、アプリケーションスレッドが GUI を更新する必要があるときに使用されます。これは、EventDispatchThread から呼び出してはいけません。次に、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();
 
ただし、doRun.run() がキャッチされない例外を (イベントディスパッチ元スレッドで) スローする場合は、その例外は呼び出し側スレッドで、InvocationTargetException としてキャッチされて再スローされるので注意してください。

このメソッドの追加のドキュメントと例については、このページを参照してください。

例外:
InterruptedException - イベントディスパッチ元スレッドが doRun.run() の実行を終えるのを待つ間に割り込みを受けた場合
InvocationTargetException - doRun.run() がスローする場合
関連項目:
invokeLater(java.lang.Runnable)

isEventDispatchThread

public static boolean isEventDispatchThread()
現在のスレッドが AWT イベントディスパッチ元スレッドの場合に true を返します。
戻り値:
現在のスレッドが AWT イベントディスパッチ元スレッドの場合は true

getAccessibleIndexInParent

public static int getAccessibleIndexInParent(Component c)
ユーザ補助機能を実装する親でのこのオブジェクトのインデックスを取得します。
戻り値:
このオブジェクトがユーザ補助機能を実装する親を持たない場合は -1。そうでない場合は、そのユーザ補助機能を実装する親での子のインデックス

getAccessibleAt

public static Accessible getAccessibleAt(Component c,
                                         Point p)
ローカル座標の Point にユーザ補助機能を実装する子が保持されている場合はそれを返します。
戻り値:
指定された位置に存在する場合はユーザ補助機能を実装する子

getAccessibleStateSet

public static AccessibleStateSet getAccessibleStateSet(Component c)
このオブジェクトの状態を取得します。
戻り値:
オブジェクトの現在の状態セットを保持する AccessibleStateSet のインスタンス
関連項目:
AccessibleState

getAccessibleChildrenCount

public static int getAccessibleChildrenCount(Component c)
オブジェクト内のユーザ補助機能を実装する子の数を返します。このオブジェクトの子のすべてが Accessible を実装する場合、このメソッドはこのオブジェクトの子の数を返さなければなりません。
戻り値:
オブジェクト内のユーザ補助機能を実装する子の数

getAccessibleChild

public static Accessible getAccessibleChild(Component c,
                                            int i)
オブジェクトのユーザ補助機能を実装する i 番目の子を返します。
パラメータ:
i - 子のゼロから始まるインデックス
戻り値:
オブジェクトのユーザ補助機能を実装する i 番目の子

findFocusOwner

public static Component findFocusOwner(Component c)
フォーカスを持つ子コンポーネントがある場合はそれを返します。HotJava SecurityManager はアプレットが getFocusOwner() にアクセスするのを禁止するので、コンポーネントがアプレットである場合は、JComponent がフォーカスを持つかどうかを調べます。HotJava でのアプレット内の Swing 以外のコンポーネントは対象外です。

getRootPane

public static JRootPane getRootPane(Component c)
c が下位 JRootPane オブジェクトの場合は、その上位 JRootPane オブジェクトを返します。c が RootPaneContainer の場合は、その JRootPane を返します。
戻り値:
Component c の JRootPane、または null

getRoot

public static Component getRoot(Component c)
現在のコンポーネントツリーのルートコンポーネントを返します。
戻り値:
Window である c の最初の上位オブジェクト、または最後の上位 Applet オブジェクト

Java プラットフォーム 1.2

バグや機能要求の報告
新しい javadoc の表示についてのコメントやご提案
Java は、米国およびその他の国における米国 Sun Microsystems, Inc. の商標もしくは登録商標です。
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.