How to make window fullscreen/maximized in Scene Builder?

前端 未结 5 1231
别跟我提以往
别跟我提以往 2021-02-03 20:03

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条回答
  • 2021-02-03 20:41

    This is the code that works for me

    primaryStage.setMaximized(true);
    

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

    0 讨论(0)
  • 2021-02-03 20:49

    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.

    0 讨论(0)
  • 2021-02-03 20:49

    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.

    0 讨论(0)
  • 2021-02-03 20:54

    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.
    0 讨论(0)
  • 2021-02-03 20:56

    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());
    
    0 讨论(0)
提交回复
热议问题