Source of ShowGridPane.java


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