我已经向我的应用程序中添加了一个自定义工具栏(我的窗口操作位于其中)。到目前为止一切都很顺利。与窗口处理有关,我正在寻找处理“全屏关闭”事件的可能性。场景:应用程序以窗口模式启动,->用户单击(自定义)工具栏按钮进入全屏。工具栏现在将其可见性设置为false。用户现在通过按钮(本机macOS按钮退出全屏)退出全屏模式->我现在需要对此做出反应(将工具栏设置为可见),但无法找到方法。
main.java
MainController mc = new MainController();
Parent root = FXMLLoader.load(getClass().getResource("welcome-view.fxml"));
stage.initStyle(StageStyle.TRANSPARENT);
mc.doSwitchScenes(stage, root);
stage.show();MainController.java
...
private String title = "Project Apollo";
private Color fillColor = TRANSPARENT;
private int minWidth = 800;
private int minHeight = 600;
...
public void btnMinimize(MouseEvent mouseEvent) {
Stage stage = (Stage)((Circle)mouseEvent.getSource()).getScene().getWindow();
// is stage minimizable into task bar. (true | false)
stage.setIconified(true);
};
public void btnCloseApp(MouseEvent mouseEvent) {
Platform.exit();
System.exit(0);
}
public void btnFullscreen(MouseEvent mouseEvent) {
Stage stage = (Stage)((Circle)mouseEvent.getSource()).getScene().getWindow();
stage.setFullScreen(true);
Scene actualScene = ((Node)mouseEvent.getSource()).getScene();
Parent hbc = (Parent) actualScene.lookup("#headerBarContainer");
if(hbc != null){
hbc.setVisible(false);
}
System.out.println("clicked FS");
}
...关键是,至少在MacOS上,窗口有其本机os控件退出全屏--是否可以针对此事件,或者至少可以更改舞台大小?
发布于 2021-12-23 13:41:17
收听stage.fullScreenProperty()并响应更改:
stage.fullScreenProperty().addListener((ChangeListener) (obs,oldValue,newValue) ->
{/*TODO respond to changes in full screen */;});https://stackoverflow.com/questions/70461895
复制相似问题