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?
5 Answers
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.
-
pity :( , I am programming an application, it must be full window. I work layouts with scene builder. It can be different space out components if its normal or full size.– Navi89CZCommented Jul 15, 2015 at 11:41
-
2You can do it, you just can't do it directly in SceneBuilder, which is a tool for designing the layout, not managing the window(s).– James_DCommented Jul 15, 2015 at 12:02
-
1@Adempiere_HotCake On which version of JavaFX are you trying to run it?
setMaximzed()
was included in JavaFX 8. Commented Sep 29, 2015 at 8:54 -
1running this with, JDK 7 , Scene builder 2.0 and Java FX Included in IntelliJ. Commented Sep 29, 2015 at 11:52
-
This method doesn't exist in JDK 7, as said above, this was included in JavaFX 8 which is a part of JDK8. Commented Sep 29, 2015 at 12:45
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());
-
I tried this. It add some extra height to the stage. I am suspecting the title bar's height. Commented Feb 12, 2017 at 7:19
-
It worked perfectly for me (running Windows 7 if that matters).– bobCommented Jul 30, 2018 at 20:13
This is the code that works for me
primaryStage.setMaximized(true);
it miximizes my window screen on the launch of the app.
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.
I agree with Yemmy1000. primaryStage.setMaximized(true) works fine for me.
primaryStage.setScene(new Scene(root, 1800, 850));
primaryStage.setMaximized(true);
This code will go to width: 1800 and height:900 when restored down from maximum.