简体   繁体   English

如何删除JavaFX按钮的多次单击事件

[英]How to remove multiple click event of javafx button

I have created a sample fx application with fxml using the scene buidler. 我已经使用场景Buidler用fxml创建了一个示例fx应用程序。 I have mapped an action handler on scene builder and write it on the java controller class. 我已经在场景生成器上映射了一个动作处理程序,并将其写在java控制器类上。 By clicking proceed button the screen will change to another screen. 单击继续按钮,屏幕将切换到另一个屏幕。 But sometime screen will get stuck at that time user will click proceed button multiple time, so the system will crash. 但是有时屏幕会卡住,这时用户将多次单击“继续”按钮,因此系统将崩溃。

I have added disable property of button at the beginning of action controller, but it is not happening. 我已经在动作控制器的开头添加了button的disable属性,但是没有发生。 How to block multiple event click event or just disable button at once clicked? 如何阻止多个事件单击事件或一次单击仅禁用按钮?

@FXML
    public void onBtnProceedClick() {
            btnProceed.setDisable(true);
          // other part of method.
}

FXML FXML

<Button fx:id="btnProceed" maxWidth="1.7976931348623157E308" mnemonicParsing="false"
    onAction="#onBtnProceedClick" prefHeight="40.0" prefWidth="-1.0"
    styleClass="btnProceed" text="" GridPane.columnIndex="1"
    GridPane.rowIndex="0"
/>

The event has a getClickCount(). 该事件具有getClickCount()。 You can add a check to say if getClickCount() > 1 then do nothing and return. 您可以添加一个检查,说getClickCount()> 1,然后什么也不做然后返回。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM