2
我正在创建一个Gluon ParticleApplication,我需要更改退出消息和/或退出过程,它在哪里或我应该重写什么? 感谢您的回答。Defaut ParticleApplication的消息在哪里?
我正在创建一个Gluon ParticleApplication,我需要更改退出消息和/或退出过程,它在哪里或我应该重写什么? 感谢您的回答。Defaut ParticleApplication的消息在哪里?
当存在退出事件(来自工具栏或菜单操作)或关闭请求事件时,当前实现使用Alert
对话框来显示消息。
虽然此对话框不是可自定义的,但有一个showCloseConfirmation
属性可让您取消该对话框,因此您可以静默地退出该应用程序,也可以提供自己的对话框。
例如,基于与胶子插件创建的默认单一的桌面项目,我们可以修改exit
行动MenuActions
下:
@Inject
ParticleApplication app;
@ActionProxy(text="Exit", accelerator="alt+F4")
private void exit() {
// disable built-in dialog
app.setShowCloseConfirmation(false);
// create a custom dialog
Alert dialog = new Alert(Alert.AlertType.CONFIRMATION, "Custom exit Message");
Optional<ButtonType> result = dialog.showAndWait();
if(result.isPresent() && result.get().equals(ButtonType.OK)) {
app.exit();
}
}
此外,您将需要处理关闭请求事件,在主类,消耗这些事件,并呼吁你的行动:
@Override
public void postInit(Scene scene) {
...
scene.windowProperty().addListener(new InvalidationListener() {
@Override
public void invalidated(Observable observable) {
scene.getWindow().setOnCloseRequest(e -> {
e.consume();
action("exit").handle(new ActionEvent());
});
scene.windowProperty().removeListener(this);
}
});
}