Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

css

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

like image 643
Yous0147 Avatar asked Jul 12 '16 10:07

Yous0147


2 Answers

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

like image 88
Yous0147 Avatar answered Oct 12 '22 10:10

Yous0147


You can take a look on modena.css:

/* ====   DISABLED THINGS   ================================================= */
.label:disabled,
.button:disabled,

 ... a lot more control here ...

.table-cell:selected:disabled,
.tree-table-cell:selected:disabled {
    -fx-opacity: 0.4;
}

This means when the disabled selector is present, it will set the -fx-opacity attribute to 0.4 from the default 1.0.

Opacity can be thought of conceptually as a postprocessing operation. Conceptually, after the node (including its descendants) is rendered into an RGBA offscreen image, the opacity setting specifies how to blend the offscreen rendering into the current composite rendering.

You can inculude this in your css, to remove the opacity change on any control:

* :disabled {
    -fx-opacity: 1;
}
like image 20
DVarga Avatar answered Oct 12 '22 10:10

DVarga