1

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!

fabian
  • 80,457
  • 12
  • 86
  • 114
dan6657
  • 117
  • 2
  • 11
  • 1
    What have you tried so far? Can you post the code that isn't working so that others can evaluate how best to fix your problem? – ManoDestra Apr 20 '16 at 13:22

2 Answers2

3

That's how you can check for the presence of a node:

gridpane.getChildren().contains(yourNode);
jns
  • 6,017
  • 2
  • 23
  • 28
1

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));
fabian
  • 80,457
  • 12
  • 86
  • 114