How to make window fullscreen/maximized in Scene Builder?
Asked Answered
D

5

41

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?

Demon answered 15/7, 2015 at 9:45 Comment(0)
S
106

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 :

Saxena answered 15/7, 2015 at 9:50 Comment(5)
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.Demon
You 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).Imray
@Adempiere_HotCake On which version of JavaFX are you trying to run it? setMaximzed() was included in JavaFX 8.Saxena
running this with, JDK 7 , Scene builder 2.0 and Java FX Included in IntelliJ.Dragon
This method doesn't exist in JDK 7, as said above, this was included in JavaFX 8 which is a part of JDK8.Saxena
P
15

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());
Piety answered 11/6, 2016 at 14:25 Comment(2)
I tried this. It add some extra height to the stage. I am suspecting the title bar's height.Zachery
It worked perfectly for me (running Windows 7 if that matters).Cedillo
J
4

This is the code that works for me

primaryStage.setMaximized(true);

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

Janettjanetta answered 19/10, 2018 at 10:5 Comment(0)
W
1

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.

Wombat answered 12/10, 2018 at 5:13 Comment(0)
T
1

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.

Tarsus answered 21/2, 2020 at 12:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.