javacssjavafx

How to disable a node without greying it out in JavaFX?


My problem is being able to disable a Node such that a user can't interact with it while I'm printing it. By the same token though, I need for the overall Node (in this case a GridPane) and all of its children (Buttons and Labels primarily) to not be interactable by the user, while the print is going on.

When I write setDisable, it greys the whole Node out, but I'd like to retain the original color and state of the Node while its disabled.

Is there a way to do this? Either through the disableProperty or other means, doesn't particularly matter to me how. The key thing here is that you shouldn't be able to interact with the Node.

Thanks in advance


Solution

  • I've found an answer:

    From @awksp "All Nodes in JavaFX have a setMouseTransparent() method, as detailed here, where the mouseTransparent property is:

    If true, this node (together with all its children) is completely transparent to mouse events. When choosing target for mouse event, nodes with mouseTransparent set to true and their subtrees won't be taken into account...."

    I then further used setFocusTraversable(false), such that you could't interact with the Node by focusing it through other means

    Thanks to @awksp for the help: https://stackoverflow.com/a/24164911/6197978