JavaFX Tutorial
This tutorial will teach you how to maximize JavaFX undecorated window. If you are developing a JavaFX application with an undecorated window design. So you’ll need this tutorial. So, let’s get this party started.
How to maximize JavaFX undecorated window
To maximize your JavaFX undecorated window application. You need to use the setMaximized(boolean) method to maximize your window in JavaFX. A boolean parameter is passed to the setMaximized(boolean) method. You have the option of using true or false. When you set the parameter to true, your JavaFX undecorated window will be maximized.
Example
stage.setMaximized(true);
Once your JavaFX undecorated window has been maximized, you can restore it to its original size. To return it to its original size, you must redefine the setMaximized() method and set the parameter to false.
To achieve the desired result. You must use the if statement. Using the if statement, create a condition. If the window is maximized, you must restore it to its original size. When the window is in its original state. Then you could maximize it again.
Example
In this example, I’ll show the entire code to maximize JavaFX undecorated window and restore the window to its original size. I’m going to use this code in the controller, and I’m going to use the mouse event.
@FXML private void Maximized_clicked(MouseEvent event) { Stage stage = (Stage) maximized_button.getScene().getWindow(); if(stage.isMaximized()){ stage.setMaximized(false); }else{ stage.setMaximized(true); } }