简体   繁体   English

获取布尔值JAVAFX

[英]Getting a Boolean value JAVAFX

I have a group of nodes within a GridPane and have some listeners adding and removing those nodes from the GridPane . 我在GridPane有一组节点,并且有一些侦听器从GridPane添加和删​​除了这些节点。

I was wondering if there is a way for me to create a get method(Boolean) or such to test if the nodes are currently in the GridPane or not. 我想知道是否有一种方法可以创建一个get方法(布尔)或类似的方法来测试节点当前是否在GridPane

I want to enable the button when the nodes aren't in the gridpane aka false . 当节点不在gridpane中也称为false时,我想启用按钮。

Any help/thoughts appreciated! 任何帮助/想法表示赞赏!

这就是检查节点是否存在的方法:

gridpane.getChildren().contains(yourNode);

You can check if the parent of the Node node that you want to check is the GridPane . 您可以检查要检查Node node的父Node node是否为GridPane This should be a bit faster than using the child list, since it does not require iterating through the child list: 这应该比使用子列表快一点,因为它不需要遍历子列表:

node.getParent() == gridPane

You can also use bindings to enable/disable the button (assuming there is a single node that decides, if the Button should be enabled or disabled) 您还可以使用绑定来启用/禁用按钮(假设有一个节点决定是否应启用或禁用Button

button.disableProperty().bind(node.parentProperty().isEqualTo(gridPane));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM