Example usage for javafx.scene.control TextField setPromptText

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

Introduction

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

Prototype

public final void setPromptText(String value) 

Source Link

Usage

From source file:Main.java

private static Node createLoginPanel() {
    final ToggleGroup toggleGroup = new ToggleGroup();

    final TextField textField = new TextField();
    textField.setPrefColumnCount(10);/*w ww.  j ava 2s . c o  m*/
    textField.setPromptText("Your name");

    final PasswordField passwordField = new PasswordField();
    passwordField.setPrefColumnCount(10);
    passwordField.setPromptText("Your password");

    final ChoiceBox<String> choiceBox = new ChoiceBox<String>(FXCollections.observableArrayList("English",
            "\u0420\u0443\u0441\u0441\u043a\u0438\u0439", "Fran\u00E7ais"));
    choiceBox.setTooltip(new Tooltip("Your language"));
    choiceBox.getSelectionModel().select(0);

    final HBox panel = createHBox(6, createVBox(2, createRadioButton("High", toggleGroup, true),
            createRadioButton("Medium", toggleGroup, false), createRadioButton("Low", toggleGroup, false)),
            createVBox(2, textField, passwordField), choiceBox);
    panel.setAlignment(Pos.BOTTOM_LEFT);
    configureBorder(panel);

    return panel;
}

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.ja  va2 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 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. co 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");

    // Define an event handler
    EventHandler handler = new EventHandler<InputEvent>() {
        public void handle(InputEvent event) {
            System.out.println("Handling event " + event.getEventType());
            event.consume();/*from   w  w w .ja v  a  2 s.co m*/
        }
    };
    scene.addEventHandler(DragEvent.DRAG_EXITED, handler);

    scene.addEventHandler(MouseEvent.MOUSE_DRAGGED, handler);

    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  a v  a 2 s . co  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 stage) {
    Group root = new Group();
    Scene scene = new Scene(root, 300, 150);
    stage.setScene(scene);/*from ww w.  j  a  v a 2 s  . c  o m*/
    stage.setTitle("Text Field Sample");

    GridPane grid = new GridPane();
    grid.setPadding(new Insets(10, 10, 10, 10));
    grid.setVgap(5);
    grid.setHgap(5);

    scene.setRoot(grid);

    final TextField name = new TextField();
    name.setPromptText("Enter your first name.");
    name.setPrefColumnCount(10);
    name.getText();
    GridPane.setConstraints(name, 0, 0);
    grid.getChildren().add(name);

    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 filter
    EventHandler filter = new EventHandler<InputEvent>() {
        public void handle(InputEvent event) {
            System.out.println("Filtering out event " + event.getEventType());
            event.consume();/*from  w  w  w. java  2 s.c o m*/
        }
    };
    // Register the same filter for two different nodes
    scene.addEventFilter(MouseEvent.MOUSE_PRESSED, filter);

    // Register the filter for another event type
    scene.addEventFilter(KeyEvent.KEY_PRESSED, filter);

    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");
    // Define an event filter
    EventHandler filter = new EventHandler<InputEvent>() {
        public void handle(InputEvent event) {
            System.out.println("Filtering out event " + event.getEventType());
            event.consume();/*from w w  w .  jav a2 s  .c  om*/
        }
    };
    // Register the same filter for two different nodes
    scene.addEventFilter(MouseEvent.MOUSE_PRESSED, filter);

    // Register the filter for another event type
    scene.addEventFilter(KeyEvent.KEY_PRESSED, filter);

    scene.removeEventFilter(MouseEvent.MOUSE_PRESSED, filter);

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

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("Simple Search");
    TextField txt = new TextField();
    txt.setPromptText("Search");
    txt.textProperty().addListener(new ChangeListener() {
        public void changed(ObservableValue observable, Object oldVal, Object newVal) {
            search((String) oldVal, (String) newVal);
        }/*from  ww w. jav  a 2 s.com*/
    });

    list.setMaxHeight(180);
    for (int i = 0; i < 100; i++) {
        entries.add("Item " + i);
    }
    entries.add("A");
    entries.add("B");
    entries.add("C");
    entries.add("D");
    list.setItems(entries);

    VBox root = new VBox();
    root.setPadding(new Insets(10, 10, 10, 10));
    root.setSpacing(2);
    root.getChildren().addAll(txt, list);
    primaryStage.setScene(new Scene(root, 300, 250));
    primaryStage.show();
}

From source file:de.perdoctus.ebikeconnect.gui.dialogs.LoginDialog.java

@PostConstruct
public void init() {
    final ImageView graphic = new ImageView(
            new Image(getClass().getResource("/app-icon.png").toExternalForm()));
    graphic.setPreserveRatio(true);/*from  w ww. j a  v a  2  s. c om*/
    graphic.setFitHeight(64);
    setGraphic(graphic);
    setResizable(true);
    setWidth(400);
    setResizable(false);

    setTitle(rb.getString("dialogTitle"));
    setHeaderText(rb.getString("dialogMessage"));

    final ButtonType loginButtonType = new ButtonType(rb.getString("loginButton"),
            ButtonBar.ButtonData.OK_DONE);
    getDialogPane().getButtonTypes().addAll(loginButtonType, ButtonType.CANCEL);

    // Create the username and password labels and fields.
    final GridPane grid = new GridPane();
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(20, 10, 10, 10));
    grid.setPrefWidth(getWidth());
    grid.getColumnConstraints().add(new ColumnConstraints(-1, -1, -1, Priority.NEVER, HPos.LEFT, true));
    grid.getColumnConstraints().add(new ColumnConstraints(-1, -1, -1, Priority.ALWAYS, HPos.LEFT, true));

    final String rbUsername = rb.getString(CFG_USERNAME);
    final TextField txtUsername = new TextField();
    txtUsername.setPromptText(rbUsername);
    txtUsername.setText(config.getString(CFG_USERNAME, ""));

    final Label lblUsername = new Label(rbUsername);
    lblUsername.setLabelFor(txtUsername);
    grid.add(lblUsername, 0, 0);
    grid.add(txtUsername, 1, 0);

    final String rbPassword = rb.getString(CFG_PASSWORD);
    final PasswordField txtPassword = new PasswordField();
    txtPassword.setPromptText(rbPassword);
    if (config.getBoolean(CFG_SAVE_PASSWORD, false)) {
        txtPassword.setText(config.getString(CFG_PASSWORD, ""));
    }

    final Label lblPassword = new Label(rbPassword);
    lblPassword.setLabelFor(txtPassword);
    grid.add(lblPassword, 0, 1);
    grid.add(txtPassword, 1, 1);

    final CheckBox cbSavePassword = new CheckBox(rb.getString("save-password"));
    cbSavePassword.setSelected(config.getBoolean(CFG_SAVE_PASSWORD, false));
    grid.add(cbSavePassword, 1, 2);

    getDialogPane().setContent(grid);

    // Enable/Disable login button depending on whether a username was entered.
    final Node loginButton = getDialogPane().lookupButton(loginButtonType);
    loginButton.disableProperty()
            .bind(txtUsername.textProperty().isEmpty().or(txtPassword.textProperty().isEmpty()));

    setResultConverter(buttonType -> {
        if (buttonType == loginButtonType) {
            config.setProperty(CFG_USERNAME, txtUsername.getText());
            config.setProperty(CFG_SAVE_PASSWORD, cbSavePassword.isSelected());
            if (cbSavePassword.isSelected()) {
                config.setProperty(CFG_PASSWORD, txtPassword.getText());
                config.setProperty(CFG_PASSWORD, txtPassword.getText());
            } else {
                config.clearProperty(CFG_PASSWORD);
            }
            return new Credentials(txtUsername.getText(), txtPassword.getText());
        } else {
            return null;
        }
    });

    if (txtUsername.getText().isEmpty()) {
        txtUsername.requestFocus();
    } else {
        txtPassword.requestFocus();
        txtPassword.selectAll();
    }
}