LoginSignup
1
2

More than 3 years have passed since last update.

JavaFXでtextFieldのフォーカスアウトイベントを実装する

Last updated at Posted at 2020-10-05

やりたいこと

  • TextField コンポーネントからフォーカスアウトしたときのイベントを実装したい。
  • フォーカスアウト時に文字を自動で置き換えたい。

やったこと

inintialize() の中で focusedProperty() に対して addListener() でイベントを追加することで、フォーカスアウト時のイベントを追加することができました。

textField1.focusedProperty().addListener(new ChangeListener<Boolean>() {
    @Override 
    public void changed(ObservableValue<? extends Boolean> arg0, Boolean oldPropertyValue,
        Boolean newPropertyValue) {
            if (!newPropertyValue) {
                textField1.setText(textField1.getText().replaceAll("髙", "高"));
            }
        }
    }
);

バージョン情報

jdk 1.8.0_144

参考

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2