Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
329 views
in Technique[技术] by (71.8m points)

java - Disabling a Button in JavaFX

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...