more examples en
    
 

STAGE, SCENE AND ROOT

API

javafx.application.Application
import javafx.geometry.HPos
import javafx.geometry.Pos
javafx.scene.Scene
javafx.stage.Stage
javafx.scene.control.Button
javafx.scene.control.TextField
javafx.scene.layout.GridPane

 

when the start method is called, it is passed a Stage object. javafx.stage.Stage represents the gui window. for any visual components to be shown an object of the type Scene is necessary. all of javafx.scene.Scene's constructors need to be passed at least an object which functions as the root node for the visual components to be displayed. in this example, that's a javafx.scene.layout.GridPane with a textfield and a button. the second and third parameters are the width and the height of the scene.

 

 1 package at.krux.javafx;

 2 import javafx.application.Application;
 3 import javafx.geometry.HPos;
 4 import javafx.geometry.Pos;
 5 import javafx.scene.Scene;
 6 import javafx.scene.control.Button;
 7 import javafx.scene.control.TextField;
 8 import javafx.scene.layout.GridPane;
 9 import javafx.stage.Stage;

10 public class StageSceneParent extends Application {

11   public static void main(String[] args) { launch(args); }

12   public void start(Stage primaryStage) {

13     GridPane pane = new GridPane();
14     TextField text = new TextField();
15     Button button = new Button("OK");

16     button.setOnAction((actionEvent) -> {
17       System.out.println(text.getText());
18     });

19     pane.add(text, 0,0);
20     pane.add(button, 0, 1);
21     pane.setAlignment(Pos.CENTER);
22     GridPane.setHalignment(button, HPos.CENTER);
23     Scene scene = new Scene(pane, 200, 200);
24     primaryStage.setScene(scene);
25     primaryStage.show();
26   }
27 }