Source of TextControlDemo.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.control.TextField;
  6: import javafx.scene.control.TextArea;
  7: import javafx.scene.control.Label;
  8: /**
  9: Demonstration of TextField and TextArea controls.
 10: */
 11: public class TextControlDemo extends Application
 12: {
 13:    public static void main(String[] args)
 14:    {
 15:       launch(args);
 16:    }
 17: 
 18:    @Override
 19:    public void start(Stage primaryStage) throws Exception
 20:    {
 21:           FlowPane root = new FlowPane();
 22:           root.setVgap(5);
 23:           root.setHgap(5);
 24: 
 25:           // Label and textfield for name
 26:           root.getChildren().add(new Label("Name"));
 27:           TextField txtName = new TextField("Enter name.");
 28:           txtName.setPrefWidth(100);
 29:           root.getChildren().add(txtName);
 30: 
 31:           // Label and textarea for info
 32:           root.getChildren().add(new Label("Your Info"));
 33:           TextArea txtInfo = new TextArea(
 34:             "Enter some information\nabout yourself.");
 35:           txtInfo.setPrefWidth(200);
 36:           txtInfo.setPrefRowCount(4);
 37:           txtInfo.setPrefColumnCount(40);
 38:           root.getChildren().add(txtInfo);
 39: 
 40:              Scene scene = new Scene(root, 450, 150);
 41:       primaryStage.setTitle("Text Control Demo");
 42:       primaryStage.setScene(scene);
 43:       primaryStage.show();
 44:    }
 45: }