2008年11月5日水曜日

Swingで任意のコンポーネントにフォーカスを設定する

JComponent#requestFocus()は非推奨のため、JComponent#requestFocusInWindow()を使用する。

[例] テキストボックスが未入力の場合にそのテキストボックスにフォーカスを設定する

if (txtBudRoot.getText().isEmpty()) {
txtBudRoot.requestFocusInWindow();
}

[参考サイト]
How to Use the Focus Subsystem
JComponent (Java Platform SE 6)

0 件のコメント: