JavaFx:对话后,两个文本字段获得焦点,而不是一个 [英] JavaFx: After dialog, two textfields gains focus instead one

查看:74
本文介绍了JavaFx:对话后,两个文本字段获得焦点,而不是一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下问题: changeListener中的指令导致两个TextField在对话框后获得Focus的行为.

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

Postleitzahl失去焦点时,会打开一个对话框.如果单击确定",则仅第一个文本字段必须获得焦点.但是真正发生的是,下面的文本字段也获得了关注.

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.

方法"controlMinChar"设置最小数量的数字. setMinCharacter方法使用该方法并使用focusedProperty

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.

推荐答案

问题是: http ://javafx-jira.kenai.com/browse/RT-28363

解决方法:

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

这篇关于JavaFx:对话后,两个文本字段获得焦点,而不是一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆