Open another window in IntelliJ using JavaFX

Tiempo de lectura: 2 minutos

Reading time: 2 minutes

To do this, we will first design one of the windows where we create a button that, when pressed, will open another window with a different design.

Each window or class in IntelliJ must have its corresponding FXML, as shown below:

In this case, our main window will be “devcodelight.fxml”, where we will find the design with a button with its id = “btn_ventana”, as follows:

Regarding the FXML code to add the button, it would be as follows:

When clicking on it, the following window will open, which in this case will have the following design:

The next step is to add the action to the button. To do this, we will add an “On Action” in the FXML:

We will create the method in the associated class (Devcodelight), declare the previously created button in case we want to modify it in the future when performing the action, and finally, simply add the following code inside the method:

We will run the application and check the result:

Leave a Comment