'Javafx stage resizeable false and maximized true hides the taskbar
In my JavaFX FXML application when I set resizable to false and maximized to true the window becomes maximized but the taskbar gets hidden. I am using Netbeans 8.0.2 on Windows 7 64 Bit with JDK 1.8.60
In Netbeans I followed the steps to create a new JavaFX FXML application. To the default code generated I added the following two lines in the start function.
stage.setResizable(false);
stage.setMaximized(true);
Hence the final start function is as below
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().
getResource("FXMLDocument.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.setResizable(false);
stage.setMaximized(true);
stage.show();
}
Now when I run the application the window is maximized, title bar is visible but the task bar is not visible. How should I fix this i.e. make the task bar visible?
Solution 1:[1]
@JC997 Has a great answer but I want to refine.
While using setWidth and setHeight you do not preventing your user from resizing the whole window. Combining setResizeable(false) with the following code won't help in that case neither.
You should apply Min and Max values to actually achieve what you are looking for, use this
Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();
stage.setX(primaryScreenBounds.getMinX());
stage.setY(primaryScreenBounds.getMinY());
stage.setMaxWidth(primaryScreenBounds.getWidth());
stage.setMinWidth(primaryScreenBounds.getWidth());
stage.setMaxHeight(primaryScreenBounds.getHeight());
stage.setMinHeight(primaryScreenBounds.getHeight());
Solution 2:[2]
If you want you're stage not resizable and maximized, with the taskbar visible, you can use this code I think:
Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();
stage.setX(primaryScreenBounds.getMinX());
stage.setY(primaryScreenBounds.getMinY());
stage.setWidth(primaryScreenBounds.getWidth());
stage.setHeight(primaryScreenBounds.getHeight());
What this does, is looking for the screen boundaries and it takes the taskbar into account.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | homerun |
| Solution 2 | JC97 |
