Source of CombinedLayout.java


  1: import javafx.application.Application;
  2: import javafx.scene.Scene;
  3: import javafx.stage.Stage;
  4: import javafx.scene.layout.FlowPane;
  5: import javafx.scene.layout.BorderPane;
  6: import javafx.scene.layout.HBox;
  7: import javafx.scene.control.TextField;
  8: import javafx.scene.control.TextArea;
  9: import javafx.scene.control.Label;
 10: import javafx.scene.control.Button;
 11: /**
 12: Embedding an HBox and FlowPane into a BorderPane.
 13: */
 14: public class CombinedLayout extends Application
 15: {
 16:    public static void main(String[] args)
 17:    {
 18:       launch(args);
 19:    }
 20: 
 21:    @Override
 22:    public void start(Stage primaryStage) throws Exception
 23:    {
 24:           BorderPane root = new BorderPane();
 25: 
 26:           // Create a FlowPane with a TextField and TextArea
 27:           FlowPane centerPane = new FlowPane();
 28:           centerPane.setVgap(5);
 29:           centerPane.setHgap(5);
 30:           // Label and textfield for name
 31:           centerPane.getChildren().add(new Label("Name"));
 32:           TextField txtName = new TextField("Enter name.");
 33:           txtName.setPrefWidth(100);
 34:           centerPane.getChildren().add(txtName);
 35:           // Label and textarea for info
 36:           centerPane.getChildren().add(new Label("Your Info"));
 37:           TextArea txtInfo = new TextArea(
 38:                   "Enter some information\nabout yourself.");
 39:           txtInfo.setPrefWidth(200);
 40:           txtInfo.setPrefRowCount(8);
 41:           txtInfo.setPrefColumnCount(40);
 42:           centerPane.getChildren().add(txtInfo);
 43: 
 44:           // Create an HBox with four buttons
 45:           HBox topPane = new HBox();
 46:           topPane.getChildren().add(new Button("This is Button 1"));
 47:           topPane.getChildren().add(new Button("This is Button 2"));
 48:           topPane.getChildren().add(new Button("This is Button 3"));
 49:           topPane.getChildren().add(new Button("This is Button 4"));
 50: 
 51:           // Add the FlowPane to the center
 52:           root.setCenter(centerPane);
 53:           // Add the HBox to the top
 54:           root.setTop(topPane);
 55: 
 56:              Scene scene = new Scene(root, 450, 250);
 57:       primaryStage.setTitle("Text Control Demo");
 58:       primaryStage.setScene(scene);
 59:       primaryStage.show();
 60:     }
 61: }