Sonja
Sonja

Reputation: 505

JavaFx: After dialog, two textfields gains focus instead one

following issue: The instruction in the changeListener leads to the behavior that two TextFields gets Focus after a Dialog.

When Postleitzahl loses focus it open a dialog. If you click OK, just first textfield have to gain the focus . But what really happen is that the textfield below gains focus too.

The method "controlMinChar" sets the minimum amount of numbers. The method setMinCharacter uses the method and uses the focusedProperty

  private void setMinCharacter(){

    plz.focusedProperty().addListener(new ChangeListener<Boolean>() {

        @Override
        public void changed(ObservableValue<? extends Boolean> ov, Boolean lostFocus, Boolean getFocus) {

            if(lostFocus){

                     generalControler.controlMinChar(plz, 5, 
                    (Stage) anchorPane.getScene().getWindow(), 
                    errorMessage);

            }

        }
    });


}

I hope you can help me. Thank you very much.

Upvotes: 1

Views: 1069

Answers (1)

Alexander Kirov
Alexander Kirov

Reputation: 3654

Issue is : http://javafx-jira.kenai.com/browse/RT-28363

Workaround :

    tf1.focusedProperty().addListener(new ChangeListener<Boolean>() {
        @Override
        public void changed(ObservableValue<? extends Boolean> ov, Boolean lostFocus, Boolean getFocus) {
            if (lostFocus) {
                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        tf1.requestFocus();
                    }
                });
            }
        }
    });

Upvotes: 1

Related Questions