在javafx中是否有焦点处理程序? [英] Is there a focus handler in javafx

查看:157
本文介绍了在javafx中是否有焦点处理程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  FocusManager.getCurrentManager()。addPropertyChangeListener(。)如果焦点发生变化, ..)

如果scenegraph中的焦点发生变化,javafx中是否有类似的方法来获得通知?

解决方案

还没有,但是您可以尝试在目标节点的focusedProperties中手动循环

  private void handleFocusChangesStartingFromParentNode(Parent parentNode){

for(Node node:parentNode.getChildrenUnmodifiable()){
node.focusedProperty ().addListener(new ChangeListener< Boolean>(){
@Override
public void changed(ObservableValue< ;? extends Boolean> observable,Boolean oldValue,Boolean newValue){
performHandling();
}
});
try {
handleFocusChangesStartingFromNode((Parent)node);
} catch(ClassCastException e){
}
}
}


In swing is a FocusManager available to get notified if the focus changes.

FocusManager.getCurrentManager().addPropertyChangeListener (...)

Is there an analogue way in javafx to get notified if the focus in the scenegraph changes?

解决方案

There's none yet but you can try manually looping among the focusedProperties of your target nodes

private void handleFocusChangesStartingFromParentNode(Parent parentNode) {

    for (Node node : parentNode.getChildrenUnmodifiable()) {
        node.focusedProperty().addListener(new ChangeListener<Boolean>() {
            @Override
            public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
                performHandling();
            }
        });
        try{
            handleFocusChangesStartingFromNode((Parent)node);
        }catch(ClassCastException e){
        }
    }
}

这篇关于在javafx中是否有焦点处理程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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