Example usage for javafx.scene.control TextField TextField

List of usage examples for javafx.scene.control TextField TextField

Introduction

In this page you can find the example usage for javafx.scene.control TextField TextField.

Prototype

public TextField() 

Source Link

Document

Creates a TextField with empty text content.

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    TextField fNameFld = new TextField();
    Label fNameLbl = new Label("First Name:");

    TextField lNameFld = new TextField();
    Label lNameLbl = new Label("Last Name:");

    GridPane root = new GridPane();
    root.addRow(0, fNameLbl, fNameFld);/*from w w  w . j  a  v  a  2s .  c  om*/
    root.addRow(1, lNameLbl, lNameFld);

    // Set a CSS for the GridPane
    root.setStyle("-fx-padding: 10;" + "-fx-border-style: solid inside;" + "-fx-border-width: 2;"
            + "-fx-border-insets: 5;" + "-fx-border-radius: 5;" + "-fx-border-color: blue;");

    Scene scene = new Scene(root);
    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    Group root = new Group();
    Scene scene = new Scene(root, 300, 250, Color.WHITE);

    TextField field = new TextField() {
        @Override//  w w w.j a  va2  s .  c o m
        public void replaceText(int start, int end, String text) {
            if (!text.matches("[a-z]")) {
                super.replaceText(start, end, text);
            }
        }

        @Override
        public void replaceSelection(String text) {
            if (!text.matches("[a-z]")) {
                super.replaceSelection(text);
            }
        }
    };

    root.getChildren().add(field);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group(), 450, 250);

    TextField notification = new TextField();
    notification.setText("Label");

    notification.clear();/*w w  w.j ava2s  . c  o  m*/

    GridPane grid = new GridPane();
    grid.setVgap(4);
    grid.setHgap(10);
    grid.setPadding(new Insets(5, 5, 5, 5));
    grid.add(new Label("To: "), 0, 0);
    grid.add(notification, 1, 0);

    Group root = (Group) scene.getRoot();
    root.getChildren().add(grid);
    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    Group root = new Group();
    Scene scene = new Scene(root, 300, 250);

    TextField textBox = new TextField();
    textBox.setPromptText("Write here");

    // Register an event handler for a single node and a specific event type
    scene.addEventHandler(DragEvent.DRAG_ENTERED, new EventHandler<DragEvent>() {
        public void handle(DragEvent e) {
            System.out.println("drag enter");
        }//from w w w .  j  av  a  2 s.c  om
    });

    root.getChildren().add(textBox);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    Group root = new Group();
    Scene scene = new Scene(root, 300, 250);

    TextField textBox = new TextField();
    textBox.setPromptText("Write here");

    // Register an event filter for a single node and a specific event type
    scene.addEventFilter(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
        public void handle(MouseEvent e) {
            System.out.println("mouse clicked");
        };// w ww . j av  a 2 s.  c  o  m
    });

    root.getChildren().add(textBox);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    Group root = new Group();
    Scene scene = new Scene(root, 300, 250);

    TextField textBox = new TextField();
    textBox.setPromptText("Write here");

    textBox.setOnKeyPressed(new EventHandler<KeyEvent>() {
        public void handle(KeyEvent ke) {
            System.out.println("Key Pressed: " + ke.getText());
        }//from  ww  w . j  av a2 s  . c o  m
    });

    textBox.setOnKeyReleased(new EventHandler<KeyEvent>() {
        public void handle(KeyEvent ke) {
            System.out.println("Key Released: " + ke.getText());
        }
    });

    root.getChildren().add(textBox);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("");
    Group root = new Group();
    Scene scene = new Scene(root, 300, 250, Color.WHITE);

    TextField field = new TextField() {
        @Override// w ww .  j  a v a 2s  .  c  o m
        public void replaceText(int start, int end, String text) {
            if (!text.matches("[a-z]")) {
                super.replaceText(start, end, text);
            }
        }

        @Override
        public void replaceSelection(String text) {
            if (!text.matches("[a-z]")) {
                super.replaceSelection(text);
            }
        }
    };

    root.getChildren().add(field);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Label nameLbl = new Label("Enter your name:");
    TextField nameFld = new TextField();

    Label msg = new Label();

    Button sayHelloBtn = new Button("Say Hello");

    sayHelloBtn.setOnAction(e -> {//from   w  ww. j  av  a 2s.  c o m
        String name = nameFld.getText();
        if (name.trim().length() > 0) {
            msg.setText("Hello " + name);
        } else {
            msg.setText("Hello there");
        }
    });

    VBox root = new VBox();

    root.setSpacing(5);

    root.getChildren().addAll(nameLbl, nameFld, msg, sayHelloBtn);

    Scene scene = new Scene(root, 350, 150);
    stage.setScene(scene);
    stage.setTitle("hi");
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Label nameLbl = new Label("Enter your name:");
    TextField nameFld = new TextField();

    Label msg = new Label();
    msg.setStyle("-fx-text-fill: blue;");

    Button sayHelloBtn = new Button("Say Hello");
    Button exitBtn = new Button("Exit");

    sayHelloBtn.setOnAction(e -> {/*from  w  ww . ja v  a 2  s  . co m*/
        String name = nameFld.getText();
        if (name.trim().length() > 0) {
            msg.setText("Hello " + name);
        } else {
            msg.setText("Hello there");
        }
    });

    exitBtn.setOnAction(e -> Platform.exit());

    VBox root = new VBox();

    root.setSpacing(5);
    root.getChildren().addAll(nameLbl, nameFld, msg, sayHelloBtn, exitBtn);

    Scene scene = new Scene(root, 350, 150);
    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    Group root = new Group();
    Scene scene = new Scene(root, 300, 250);

    TextField textBox = new TextField();
    textBox.setPromptText("Write here");

    // Define an event handler
    EventHandler handler = new EventHandler<InputEvent>() {
        public void handle(InputEvent event) {
            System.out.println("Handling event " + event.getEventType());
            event.consume();// www .j ava 2 s  .com
        }
    };
    scene.addEventHandler(DragEvent.DRAG_EXITED, handler);

    scene.addEventHandler(MouseEvent.MOUSE_DRAGGED, handler);

    root.getChildren().add(textBox);
    primaryStage.setScene(scene);
    primaryStage.show();
}