如何在不使用alert.initOwner()
的情况下将程序图标设置为提醒? 为什么没有initOwner
?这是因为在整个窗口初始化之前必须显示一些警报,所以没有可以使用initOwner
函数的场景。JavaFX 8如何设置程序图标以提醒?
2
A
回答
2
您可以从Alert实例中窃取DialogPane,并将其添加到常规舞台。一个节点只能是一次一个场景的根,所以你需要先更换警报的场景的根:
public class AlertWithIcon
extends Application {
@Override
public void start(Stage stage) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION,
"Are you sure you want to delete this item?",
ButtonType.YES, ButtonType.NO);
alert.setHeaderText("Delete Item");
DialogPane pane = alert.getDialogPane();
ObjectProperty<ButtonType> result = new SimpleObjectProperty<>();
for (ButtonType type : pane.getButtonTypes()) {
ButtonType resultValue = type;
((Button) pane.lookupButton(type)).setOnAction(e -> {
result.set(resultValue);
pane.getScene().getWindow().hide();
});
}
pane.getScene().setRoot(new Label());
Scene scene = new Scene(pane);
Stage dialog = new Stage();
dialog.setScene(scene);
dialog.setTitle("Delete Item");
dialog.getIcons().add(new Image("GenericApp.png"));
result.set(null);
dialog.showAndWait();
System.out.println("Result is " + result);
}
}
2
public class AlertWithIcon
extends Application {
@Override
public void start(Stage stage) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION,
"Are you sure you want to delete this item?",
ButtonType.YES, ButtonType.NO);
alert.setHeaderText("Delete Item");
((Stage)alert.getDialogPane().getScene().getWindow()).getIcons().add(new image("GenericApp.png"));
alert.showAndWait();
}
}
0
这是它是如何做:
// Get the Stage.
Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
// Add a custom icon.
stage.getIcons().stage.getIcons().add(new Image("images/logo_full3.png"));
上面的图片引用可能有问题。但是,只要它能够工作,您就可以尝试进行配置。这是我的方式(我使用maven)。如果你不使用maven,你的可能会有所不同。
完整教程在这里:Alert javafx tutorial
相关问题
- 1. 如何设置提醒?
- 2. iOS提醒应用程序可以根据特定日期设置提醒
- 3. 如何简单地设置在MS Access中设置日期的提醒/提醒?
- 4. Javascript提醒窗口 - 如何设置len
- 5. 如何通过Slack API设置提醒?
- 6. 如何设置程序的图标?
- 7. 使用JavaFX设置应用程序图标时遇到问题
- 8. JavaFX应用程序图标
- 9. 设置Outlook日历提醒
- 10. 如何实现提醒应用程序?
- 11. 如何以编程方式将提醒设置为特定日期
- 12. 在iOS应用程序的背景中设置提醒
- 13. 以编程方式将提醒添加到提醒应用程序
- 14. 如何设置TableColumnValue JavaFX的表视图
- 15. 如何在VB中设置每月提醒提示的时间
- 16. Android提醒应用程序
- 17. 提醒应用程序
- 18. 如何在iPhone的提醒应用程序中以编程方式添加提醒?
- 19. 如何以编程方式设置应用程序池标识
- 20. 如何添加提醒/提醒类型的通知,提醒用户一旦设置在C#/ XAML地铁应用程序?
- 21. 如何提醒
- 22. 如何为摆动应用程序设置图标图像?
- 23. JavaFX 8任务栏图标监听器
- 24. JavaFX中的应用程序图标
- 25. Android:计算时间来设置提醒
- 26. 设置在农闲提醒链接
- 27. Firebase:从firebase自动设置提醒
- 28. 提醒应用程序 - 重复某个提醒
- 29. 提醒用户评价应用程序的提醒
- 30. 从My.Resources设置应用程序图标?
不错!这是我一直在寻找的东西,谢谢:D –