|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 前のクラス 次のクラス | フレームあり フレームなし | |||||||||
| 概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド | |||||||||
java.lang.Objectjavax.swing.SwingUtilities
public class SwingUtilities
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)
rectA 内で rectB とオーバーラップしない領域を表現する矩形の配列を返すのに便利です。 |
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)
その 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 座標体系の 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)
UI が component の condition に指定した 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)
単純な Look & Feel の変更で、ツリー内の各ノードに updateUI() 処理を行うこと、つまり現在の Look & Feel でその 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 |
| メソッドの詳細 |
|---|
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 を親として持つ、最下位の可視コンポーネントを返します。parent が指定された位置を内包していない場合は、null が返されます。parent がコンテナではない場合、あるいは parent の可視の子がどれも指定された位置を内包していない場合は、parent が返されます。
parent - 検索を開始するルートコンポーネントx - x ターゲット位置y - y ターゲット位置
public static MouseEvent convertMouseEvent(Component source,
MouseEvent sourceEvent,
Component destination)
destination の座標体系に変換済みの場合を除いて、sourceEvent と同様の MouseEvent を返します。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 番目の矩形
dest
public static Rectangle computeUnion(int x,
int y,
int width,
int height,
Rectangle dest)
x - 最初の矩形の x 座標y - 最初の矩形の y 座標width - 最初の矩形の幅height - 最初の矩形の高さdest - 2 番目の矩形の座標。 2 つの矩形の和集合がこの矩形で返される
dest Rectangle
public static Rectangle[] computeDifference(Rectangle rectA,
Rectangle rectB)
rectA 内で rectB とオーバーラップしない領域を表現する矩形の配列を返すのに便利です。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 - 計算対象の String
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 で、コンポーネントをペイントします。このメソッドは、主に可視の包含関係の階層には含まれていないが描画に使用される Component を描画するために使用されます。たとえば、描画時にテキストや HTML を描画したい場合は、JLabel のテキスト描画機能を利用して、このメソッドで直接ペイントすることができます。このとき、ラベルを可視の包含関係の階層に追加する必要はありません。
このメソッドは、CellRendererPane を利用して、実際のペイントを処理します。描画に単一のコンポーネントを使用する場合にのみ使用するようにしてください。JTable のように複数のコンポーネントを利用して描画を行う場合は、CellRendererPane を直接使用してください。そうでない場合は、次に示すように、Component ごとに CellRendererPane を呼び出します。
c の親が CellRendererPane でない場合、新しい CellRendererPane が作成され、それに c が追加されます。また、CellRendererPane が p に追加されます。c の親が CellRendererPane であり、CellRendererPane の親が p でない場合、CellRendererPane が 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() がキャッチされない例外をスローする場合は、イベントディスパッチスレッド (現在のスレッドではない) が状態を元に戻します。
このメソッドの追加のドキュメントと例については、「The Java Tutorial」の「How to Use Threads」を参照してください。
JDK Version 1.3 以降、このメソッドは java.awt.EventQueue.invokeLater() を呼び出すだけです。
このメソッドは、ほかの Swing のメソッドとは異なり、どのスレッドからでも呼び出せます。
invokeAndWait(java.lang.Runnable)
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();
Runnable.run メソッドがキャッチされない例外をイベントディスパッチ元スレッドでスローする場合は、その例外は呼び出し側のスレッドで、InvocationTargetException としてキャッチされて再スローされるため、注意してください。
このメソッドの追加のドキュメントと例については、「The Java Tutorial」の「How to Use Threads」を参照してください。
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 がフォーカス所有者である場合、その子 Component を返します。
c - フォーカス所有者を検索するときの Component 階層のルート
comp でない場合、またはフォーカス所有者が comp の子である場合は nullKeyboardFocusManager.getFocusOwner()public static JRootPane getRootPane(Component c)
nullpublic 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 のインスタンス。 null の場合もある
null の場合は null。 そうでない場合は渡された矩形 (null 以外の場合)、 または位置およびサイズ情報を指定する新しい矩形
|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 前のクラス 次のクラス | フレームあり フレームなし | |||||||||
| 概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド | |||||||||
Copyright 2009 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Documentation Redistribution Policy も参照してください。