Disabling a Button in JavaFX


Question

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.

1
45
7/26/2013 1:14:16 AM

Accepted Answer

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)
74
10/2/2018 9:47:38 AM

You have 2 choices if you want the button disabled you can just

Button.setDisable(true);

or if you want you can also make it invisible

Button.setVisible(false);

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon