1  import javafx.application.Application;
  2  import javafx.geometry.HPos;
  3  import javafx.geometry.Insets;
  4  import javafx.geometry.Pos;
  5  import javafx.scene.Scene;
  6  import javafx.scene.control.Button;
  7  import javafx.scene.control.Label;
  8  import javafx.scene.control.TextField;
  9  import javafx.scene.layout.GridPane;
 10  import javafx.stage.Stage;
 11  
 12  public class ShowGridPane extends Application {
 13    @Override // Override the start method in the Application class
 14    public void start(Stage primaryStage) {
 15      // Create a pane and set its properties
 16      GridPane pane = new GridPane();
 17      pane.setAlignment(Pos.CENTER); // Set center alignment
 18      pane.setPadding(new Insets(11.5, 12.5, 13.5, 14.5));
 19      pane.setHgap(5.5);
 20      pane.setVgap(5.5); // Set vGap to 5.5px
 21      
 22      // Place nodes in the pane
 23      pane.add(new Label("First Name:"), 0, 0);
 24      pane.add(new TextField(), 1, 0);
 25      pane.add(new Label("MI:"), 0, 1); 
 26      pane.add(new TextField(), 1, 1);
 27      pane.add(new Label("Last Name:"), 0, 2);
 28      pane.add(new TextField(), 1, 2);
 29      Button btAdd = new Button("Add Name");
 30      pane.add(btAdd, 1, 3);
 31      GridPane.setHalignment(btAdd, HPos.RIGHT);
 32      
 33      // Create a scene and place it in the stage
 34      Scene scene = new Scene(pane);
 35      primaryStage.setTitle("ShowGridPane"); // Set the stage title
 36      primaryStage.setScene(scene); // Place the scene in the stage
 37      primaryStage.show(); // Display the stage
 38    }
 39    
 40    /**
 41     * The main method is only needed for the IDE with limited
 42     * JavaFX support. Not needed for running from the command line.
 43     */
 44    public static void main(String[] args) {
 45      launch(args);
 46    }
 47  }