Alert in JAVA FX

后端 未结 2 1714
我寻月下人不归
我寻月下人不归 2021-01-24 04:45

I want to display an alert when a file already exists when trying to create the file with same name . I have not completed the code fully. I want to retrieve the button value Ye

2条回答
  •  借酒劲吻你
    2021-01-24 05:02

    Simply use the Alert class. It provides functionality for most yes/no dialogs that you ever need.

    Alert alert = new Alert(AlertType.WARNING, 
                            "File already exists. Do you want to override?", 
                            ButtonType.YES, ButtonType.NO);
    
    Optional result = alert.showAndWait();
    if (result.get() == ButtonType.YES){
        // ... user chose YES
    } else {
        // ... user chose NO or closed the dialog
    }
    

    Also here is a good tutorial.

提交回复
热议问题