Disabling a Button in JavaFX

JavaUser InterfaceJavafx

Java Problem Overview


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.

Java Solutions


Solution 1 - Java

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)

Solution 2 - Java

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);

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTarif HaqueView Question on Stackoverflow
Solution 1 - JavaEugene RyzhikovView Answer on Stackoverflow
Solution 2 - JavaMontassar BouajinaView Answer on Stackoverflow