在JavaFX中禁用按钮 [英] Disabling a Button in JavaFX
本文介绍了在JavaFX中禁用按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Swing中,我们可以禁用这样的按钮:
In Swing, we can disable a button like this:
JButton start = new JButton("Start");
start.setEnabled(false);
无论如何使用JavaFX Button执行此操作?
用户应该只能按一次按钮。
Is there anyway to do this with a JavaFX Button? The user should only be able to press the button once.
推荐答案
当然。只有相关的属性具有相反的语义,并且被称为已禁用
。这意味着你可以使用 setDisable
(不是 setDisabled
)和 isDisabled
。由于它是JavaFX属性,您还可以将侦听器附加到 disabledProperty
。
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
.
查看 http://docs.oracle.com/javafx /2/api/javafx/scene/Node.html#setDisable(boolean)
代码
button.setDisable(false)
这篇关于在JavaFX中禁用按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文