Run the code:
@Override
public void start(Stage stage) throws Exception {
final TextField tf1 = new TextField("text1"), tf2 = new TextField("text2");
tf1.focusedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> ov, Boolean lostFocus, Boolean getFocus) {
if (lostFocus) {
tf1.requestFocus();
}
}
});
stage.setScene(new Scene(new VBox(tf1, tf2), 300, 300));
stage.show();
}
Initially, text field 1 has a focus. Press TAB. Both textFields will be focused (visually), but only the first one will receive input, press tab again, and the second control will start to receive keyboard input, but they both will still be visually focused.
Test case is from : http://stackoverflow.com/questions/14841622/javafx-after-dialog-two-textfields-gains-focus-instead-one
Situation can be observed here : http://www.fotos-hochladen.net/view/focus2cd7ioyvr3g.png
@Override
public void start(Stage stage) throws Exception {
final TextField tf1 = new TextField("text1"), tf2 = new TextField("text2");
tf1.focusedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> ov, Boolean lostFocus, Boolean getFocus) {
if (lostFocus) {
tf1.requestFocus();
}
}
});
stage.setScene(new Scene(new VBox(tf1, tf2), 300, 300));
stage.show();
}
Initially, text field 1 has a focus. Press TAB. Both textFields will be focused (visually), but only the first one will receive input, press tab again, and the second control will start to receive keyboard input, but they both will still be visually focused.
Test case is from : http://stackoverflow.com/questions/14841622/javafx-after-dialog-two-textfields-gains-focus-instead-one
Situation can be observed here : http://www.fotos-hochladen.net/view/focus2cd7ioyvr3g.png
- duplicates
-
JDK-8120738 When requesting focus on a focusproperty changed listener, javafx gives focus to two different controls
-
- Closed
-
- relates to
-
JDK-8124925 Focus rectangle draws on more than one Tab in a TabPane at the same time
-
- Closed
-