【问题标题】:Display alerts when clicked on JavaFX单击 JavaFX 时显示警报
【发布时间】:2016-08-10 22:27:43
【问题描述】:

我的 JavaFX 程序上有一个名为 woodcuttingButton 的按钮,当单击它时,它会提醒玩家选择他们想要砍伐的树。

不幸的是,当单击按钮时,什么也没有发生。

woodcuttingButton.setOnAction(e -> {
            alert.setTitle("Woodcutting");
            alert.setHeaderText("What tree would you like to cut?");
            alert.setContentText("Choose your option.");

            ButtonType buttonTypeOak = new ButtonType("Oak");
            ButtonType buttonTypeWillow = new ButtonType("Willow");
            ButtonType buttonTypeMaple = new ButtonType("Maple");
            ButtonType buttonTypeCancel = new ButtonType("Cancel", ButtonData.CANCEL_CLOSE);

            alert.getButtonTypes().setAll(buttonTypeOak, buttonTypeWillow, buttonTypeMaple, buttonTypeCancel);
        });

我是否错误地执行了警报?

【问题讨论】:

  • 在我看来像 runescape 哈哈

标签: java button javafx


【解决方案1】:

它已正确实现(至少您已经展示过),但您需要显示对话框

alert.showAndWait();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-15
    • 1970-01-01
    • 2015-07-15
    • 2018-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多