The Stage
In JavaFX the The user interface is the 'Stage'. Like in a theater, the stage is where all the events will be presented to the audiences or the users.
To create a JavaFX application on IntelliJ, you simply have to create a new JavaFX class.
|
Creating JavaFX application |
After you created the JavaFX application, you can see, there is a start method to be implemented. For now the curtains of the stage is still closed. You can open the curtains by adding
primaryStage.show();
to the start method.
|
adding show method to open the stage |
If you now run the application, you'll see an empty 'stage'. The stage is there, now it is up to you to perform a show
The Scene
Now that you have a stage, you might want to perform a show. To do that, you'll need a scene. In a scene, there are some props or in Java terms, 'nodes'. A node can be a button, text field or just a label. To create a good scene you might want all these nodes to be organized nicely. Some nodes that build one feature, should also be placed side by side so the user will know intuitively what these nodes are about. Nodes is organized in a class called
Parent. In Web term, it is similar to
div
tags. You can organize the nodes vertically using
VBox Parent or horizontally using
HBox Parent.
Layouts
BorderPane
BorderPane is a layout with five areas: Top, left, center, right and bottom.
GridPane
As the name said, GridPane works with grid system.
|
use indexes to organize the nodes |
|
use hgap and vgap to control the space between grid |
|
when there is not enough space, the nodes will shrink to fit the window |