JavaFx: After dialog, two textfields gains focus instead one

天涯浪子 提交于 2019-12-24 11:54:20

问题


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.


回答1:


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();
                    }
                });
            }
        }
    });


来源:https://stackoverflow.com/questions/14841622/javafx-after-dialog-two-textfields-gains-focus-instead-one

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!