Node.setDisable () vs setDisabled () in JavaFX

There are two methods to call when inheriting from javafx.scene.Node : (I show the current implementation of Oracle 8u66)

setDisable(boolean)

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

setDisabled(boolean)

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

What should I call when inheriting from javafx.scene.Node ?

+5
source share
2 answers

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

In JavaFX, a node appears 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 node clients, reflects this general state: i.e. disabled is true if and only if disable is true for this node or for any of its ancestor nodes (containers).

So, to disable node, you usually call setDisable(true); . In a custom subclass of Node you should only call setDisabled(true); to enforce the rule described above. Please note that the implementation of the superclass will already apply this rule, so if you are not doing something very complicated (I can’t even see an example of use), you will not need to call setDisabled(...) .

+8
source

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

Quote from this comment by @jewelsea .

+3
source

Source: https://habr.com/ru/post/1238724/


All Articles