Search code examples
framestagejavafx-2maximize-window

How to set a JavaFX Stage/Frame to Maximized


I'm using JavaFX 2. I want my frame to open maximized but I'm not seeing a way. I searched a bit on the internet without success. For the stage I see setFullScreen() and setIconified() but I don't see anything like setMaximized().


Solution

  • When evaluating the sourcecode of the Ensemble.jar provided with the samples of JavaFX 2.0 SDK, the currently valid way to achieve window maximizing is

    Screen screen = Screen.getPrimary();
    Rectangle2D bounds = screen.getVisualBounds();
    
    primaryStage.setX(bounds.getMinX());
    primaryStage.setY(bounds.getMinY());
    primaryStage.setWidth(bounds.getWidth());
    primaryStage.setHeight(bounds.getHeight());
    

    (you find similar code in WindowButtons.java)

    The 'maximize' button is still enabled and when clicking it, the windows will grow a bit more (Windows OS). After this the 'maximize 'button is disabled. In the provided example the standard buttons are replaced. Maybe this is still an issue.