Disabling a Button in JavaFX

Tarif Haque picture Tarif Haque · Jul 26, 2013 · Viewed 93.8k times · Source

In Swing, we can disable a button like this:

JButton start = new JButton("Start");
start.setEnabled(false);

Is there anyway to do this with a JavaFX Button? The user should only be able to press the button once.

Answer

Eugene Ryzhikov picture Eugene Ryzhikov · Jul 26, 2013

Of course. Only related property has opposite semantic and is called disabled. Which means you can use setDisable (not setDisabled) and isDisabled. Since it is a JavaFX property you can also attach listeners to disabledProperty.

Check out the JavaFX documentation at http://docs.oracle.com/javafx/2/api/javafx/scene/Node.html#setDisable(boolean)

Code

button.setDisable(false)