7

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

DVarga
  • 21,311
  • 6
  • 55
  • 60
Yous0147
  • 301
  • 3
  • 10
  • I would mention also to add a ProgressIndicator or an Animation so the user can see that something is going on. – GOXR3PLUS Jul 12 '16 at 11:12

6 Answers6

10

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

Community
  • 1
  • 1
Yous0147
  • 301
  • 3
  • 10
  • 1
    Still won't help on touch and gesture events. – Mordechai Sep 22 '16 at 05:31
  • Haven't specifically tested that, but I try to recall a similar case I once had. Maybe I'm wrong, though. – Mordechai Sep 22 '16 at 05:36
  • 1
    Could also try setting the Node's event dispatcher to null during the print, then back to the event dispatcher that was assigned before you set it to null, after print. I believe that should handle both touch and mouse (any InputEvent) events. @see Node.setEventDispatcher(EventDispatcher) – Adrian Romanelli Mar 15 '18 at 20:25
7

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;
}
DVarga
  • 21,311
  • 6
  • 55
  • 60
  • 1
    Thanks for the answer. I indeed did try to reload a new stylesheet after setting disable to true by using `setStyle("-fx-opacity: 1;")` and altering opacity, but for some reason it didn't alter it. I've found another solution, but thank you for the help. – Yous0147 Jul 12 '16 at 10:50
4

css can solve your problem use disabled property. and change background and text color. following is the css of combobox but you can take some part of it.

.transparent:disabled, .transparent:disabled .arrow-button .arrow, .transparent:disabled .combo-box-base {
     -fx-background-color: #ffffff;
     -fx-opacity: 1;
     -fx-text-fill:#000000;
 }

for more info please see below link of css reference guide in javafx

https://docs.oracle.com/javafx/2/api/javafx/scene/doc-files/cssref.html

mcd
  • 1,434
  • 15
  • 31
  • Thanks for the help. For the time being I'll be using another solution as it's the easiest for me and seems to work without problems. If it corks out later on, then I'll be sure to come back redo the code using yours and @DVarga 's solution. – Yous0147 Jul 12 '16 at 11:07
2

In my case, I was making TicTacToe game, there I needed the button to be disabled after pressing it, but the opacity to be same as before.So I just set the opacity.

Like this...

 public void actions(){
       one.setOnMouseClicked(e->{
               one.setText("X");
               one.setDisable(true);
               one.setOpacity(1);
       });

}

I hope it may help someone.

Pratham Sarankar
  • 555
  • 6
  • 10
0

If you want to make a particular Pane not to grayed out, you can add the below CSS Stylesheet to it.

JavaFX

node.getStyleClass().add("pane_opacity");

CSS

.pane_opacity:disabled .label:disabled,
.pane_opacity:disabled .button:disabled,
.pane_opacity:disabled .toggle-button:disabled,
.pane_opacity:disabled .radio-button:disabled,
.pane_opacity:disabled .check-box:disabled,
.pane_opacity:disabled .hyperlink:disabled,
.pane_opacity:disabled .menu-button:disabled,
.pane_opacity:disabled .split-menu-button:disabled,
.pane_opacity:disabled .slider:disabled,
.pane_opacity:disabled .scroll-bar:disabled,
.pane_opacity:disabled .scroll-pane:disabled,
.pane_opacity:disabled .progress-bar:disabled,
.pane_opacity:disabled .progress-indicator:disabled,
.pane_opacity:disabled .text-input:disabled,
.pane_opacity:disabled .choice-box:disabled,
.pane_opacity:disabled .combo-box-base:disabled,
.pane_opacity:disabled .date-cell:disabled > *, /* This is set on children so border is not affected. */
.pane_opacity:disabled .list-view:disabled,
.pane_opacity:disabled .tree-view:disabled,
.pane_opacity:disabled .table-view:disabled,
.pane_opacity:disabled .tree-table-view:disabled,
.pane_opacity:disabled .tab-pane:disabled,
.pane_opacity:disabled .titled-pane:disabled > .title,
.pane_opacity:disabled .accordion:disabled > .titled-pane > .title,
.pane_opacity:disabled .tab-pane > .tab-header-area > .headers-region > .tab:disabled,
.pane_opacity:disabled .menu:disabled,
.pane_opacity:disabled .menu-item:disabled > .label,
.pane_opacity:disabled .menu-item:disabled,
.pane_opacity:disabled .list-cell:filled:selected:focused:disabled,
.pane_opacity:disabled .list-cell:filled:selected:disabled,
.pane_opacity:disabled .tree-cell:filled:selected:focused:disabled,
.pane_opacity:disabled .tree-cell:filled:selected:disabled,
.pane_opacity:disabled .tree-cell > .tree-disclosure-node:disabled,
.pane_opacity:disabled .tree-table-row-cell > .tree-disclosure-node:disabled,
.pane_opacity:disabled .table-row-cell:selected:disabled,
.pane_opacity:disabled .tree-table-row-cell:selected:disabled,
.pane_opacity:disabled .table-cell:selected:disabled,
.pane_opacity:disabled .tree-table-cell:selected:disabled {
    -fx-opacity: 1;
}
javasuns
  • 1,061
  • 2
  • 11
  • 22
0

Use node.setDisable(true); to disable the node, use node.setStyle("-fx-opacity: 1"); to prevent the node from losing its opacity.

Arthur Khazbs
  • 705
  • 8
  • 19