J
J
Javilingys2019-10-20 15:01:01
Java
Javilingys, 2019-10-20 15:01:01

How to do something when opening a window in JavaFX FXML?

Hello, I started to understand JavaFX and FXML)
There was such a question, how in JavaFX + FXML to launch some kind of action immediately after the application starts?
Those. without any buttons, etc., I just want the for loop to create 10 rectangls immediately after the application starts, but I don’t understand how, because I only know how to do it by clicking on the button)
I have an empty template with a fxml file, a controller and an App class..

<BorderPane xmlns="http://javafx.com/javafx"
            xmlns:fx="http://javafx.com/fxml"
            fx:controller="org.javilingys.MiniPlayerController"
            prefHeight="400.0" prefWidth="600.0"
            stylesheets="css/stylesheet.css">
</BorderPane>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Alexandrov, 2019-10-20
@Javilingys

In the case of FXML, you still cannot access fxml elements from the controller constructor, but there is an initialize () method that works after the entire fxml has been initialized, use it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question