Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.setDisable() vs setDisabled() in JavaFX

Tags:

java

javafx

There are two methods available for calling when inheriting from javafx.scene.Node: (I am showing off the current 8u66 Oracle implementation)

setDisable(boolean)

public final void setDisable(boolean value) {
    disableProperty().set(value);
}

setDisabled(boolean)

protected final void setDisabled(boolean value) {
    disabledPropertyImpl().set(value);
}

Which one should I call when inheriting from javafx.scene.Node?

like image 292
randers Avatar asked Dec 19 '15 19:12

randers


2 Answers

It depends a bit on the context, but you almost certainly want to call setDisable(...).

In JavaFX, a node is rendered as disabled, and ignores any user input, if its disable property is true, or if the disable property is true for any ancestor in the scene graph. The disabled property, which is a read-only property for clients of the node, reflects this overall state: i.e. disabled is true if and only if disable is true for this node or for any of its ancestor (container) nodes.

So to disable a node, you should typically call setDisable(true);. In a custom subclass of Node, you should only call setDisabled(true); to enforce the rule described above. Note that the superclass implementation will already enforce this rule, so unless you are doing something very complex (I can't even really see a use case), you will not need to call setDisabled(...).

like image 137
James_D Avatar answered Oct 25 '22 17:10

James_D


You want to use setDisable, not setDisabled. setDisable is a public method for disabling a node, setDisabled is a protected method used only by internal implementations.

Quoted from this comment by user @jewelsea.

like image 21
randers Avatar answered Oct 25 '22 18:10

randers