public class GridPaneDemo extends Application
1: import javafx.application.Application;
2: import javafx.scene.Scene;
3: import javafx.stage.Stage;
4: import javafx.scene.layout.GridPane;
5: import javafx.geometry.HPos;
6: import javafx.scene.control.Button;
7: import javafx.scene.control.Label;
8: import javafx.geometry.Insets;
9: /**
10: Simple demonstration of adding buttons and labels
11: to the GridPane layout.
12: */
13: public class GridPaneDemo extends Application
14: {
15: public static void main(String[] args)
16: {
17: launch(args);
18: }
19:
20: @Override
21: public void start(Stage primaryStage) throws Exception
22: {
23: GridPane root = new GridPane();
24:
25: // Set a gap of 5 pixels vertically and horizontally
26: // between elements
27: root.setVgap(5);
28: root.setHgap(5);
29: // Margins around the top, right, bottom, and left
30: root.setPadding(new Insets(10,10,10,10));
31:
32: // Add three nodes, by default horizontally left-aligned
33: root.add(new Label("Option 1"),0,0);
34: root.add(new Button("This is Button 1"),1,0);
35: root.add(new Label("Option 2"),0,1);
36:
37: // Add a button that is horizontally right-aligned
38: Button btn2 = new Button("Button 2");
39: GridPane.setHalignment(btn2, HPos.RIGHT);
40: root.add(btn2,1,1);
41:
42: // Add a label to the bottom right of the buttons
43: root.add(new Label("Out there"),2,2);
44:
45: Scene scene = new Scene(root, 500, 200);
46: primaryStage.setTitle("GridPane Demo");
47: primaryStage.setScene(scene);
48: primaryStage.show();
49: }
50: }