Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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().

like image 461
Dorothy Avatar asked Jul 28 '11 19:07

Dorothy


People also ask

What does JavaFX stage stage do?

A Stage in JavaFX is a top-level container that hosts a Scene, which consists of visual elements. The Stage class in the javafx. stage package represents a stage in a JavaFX application. The primary stage is created by the platform and passed to the start(Stage s) method of the Application class.


2 Answers

The Java 8 implementation of the Stage class provides a maximized property, which can be set as follows:

primaryStage.setMaximized(true); 
like image 106
Hans Avatar answered Sep 19 '22 04:09

Hans


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.

like image 33
pmoule Avatar answered Sep 21 '22 04:09

pmoule