How to make window fullscreen/maximized in Scene Builder?

一个人想着一个人 提交于 2019-12-03 10:43:37

问题


I am making a view in SceneBuilder for my JavaFX application. I want my view to be maximized. How can I achieve this in SceneBuilder or the .fxml file?


回答1:


You cannot do that using Scene Builder, since maximize or fullScreen are properties of the Stage and not the layouts set on the scene.

You can load and set the .fxml on the scene and later set the scene on the stage.

The following methods can be used on the stage :

  • setMaximized(boolean) - To maximize the stage and fill the screen.
  • setFullScreen(boolean) - To set stage as full-screen, undecorated window.



回答2:


As you cannot maximize your view in fxml, you have to set the size of the stage to be maximized. There is no direct method for setting the size of the stage to be maximized in javafx 2 but there is another way you can do this. It is by manually setting the size of the stage. You can use this code:

Screen screen = Screen.getPrimary();
Rectangle2D bounds = screen.getVisualBounds();

primaryStage.setX(bounds.getMinX());
primaryStage.setY(bounds.getMinY());
primaryStage.setWidth(bounds.getWidth());
primaryStage.setHeight(bounds.getHeight());



回答3:


Two properties I found in stage which are useful. First is setFullScreen(boolean) which will set your view to full screeb, but it will also hide all the taskbar and header of view.

Second is setMaximized(boolean) which will set you view to perfect like any other application view size.

I an using setMaximized(true) for my application.




回答4:


This is the code that works for me

primaryStage.setMaximized(true);

it miximizes my window screen on the launch of the app.



来源:https://stackoverflow.com/questions/31426912/how-to-make-window-fullscreen-maximized-in-scene-builder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!