I have a group of nodes within a GridPane
and have some listeners adding and removing those nodes from the 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.
I want to enable the button when the nodes aren't in the gridpane aka 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
. 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.disableProperty().bind(node.parentProperty().isEqualTo(gridPane));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.