Example usage for javafx.scene.control TextField setText

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

Introduction

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

Prototype

public final void setText(String value) 

Source Link

Usage

From source file:mesclasses.controller.PageController.java

public static final void markAsHour(TextField field) {
    field.textProperty().addListener((observable, oldValue, newValue) -> {
        if (StringUtils.isBlank(newValue)) {
            return;
        }/*from w  w  w  .  j  a  v  a 2 s . c  o  m*/
        if (!StringUtils.isNumeric(newValue.substring(newValue.length() - 1))) {
            field.setText(newValue.substring(0, newValue.length() - 1));
            return;
        }
        if (newValue.length() > 2) {
            field.setText(oldValue);
            return;
        }
        if (Integer.parseInt(newValue) > 23) {
            field.setText("23");
        }

    });
}

From source file:mesclasses.controller.PageController.java

public static final void markAsMin(TextField field) {
    field.textProperty().addListener((observable, oldValue, newValue) -> {
        if (StringUtils.isBlank(newValue)) {
            return;
        }//from   ww  w.ja  v  a  2s.  c  om
        if (!StringUtils.isNumeric(newValue.substring(newValue.length() - 1))) {
            field.setText(newValue.substring(0, newValue.length() - 1));
            return;
        }
        if (newValue.length() > 2) {
            field.setText(oldValue);
            return;
        }
        if (Integer.parseInt(newValue) > 59) {
            field.setText("59");
        }

    });
}

From source file:com.anavationllc.o2jb.ConfigurationApp.java

private static void addTextLimiter(final TextField tf, final int maxLength) {
    tf.textProperty().addListener(new ChangeListener<String>() {
        @Override// w  w  w.j av a 2 s .c  o  m
        public void changed(final ObservableValue<? extends String> ov, final String oldValue,
                final String newValue) {
            if (tf.getText().length() > maxLength) {
                String s = tf.getText().substring(0, maxLength);
                tf.setText(s);
            }
        }
    });
}

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 ww .  j  av  a 2s.  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 stage) {
    stage.setTitle("ComboBoxSample");
    Scene scene = new Scene(new Group(), 450, 250);

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

    notification.clear();//  w  w w.j  a  v  a 2  s.  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: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);//  w  ww.j a v a 2s .  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();
    }
}

From source file:de.rkl.tools.tzconv.TimezoneConverter.java

private Node createTemplateNameField() {
    final TextField templateNameField = new TextField();
    templateNameField.setEditable(false);
    final File templateFile = applicationModel.templateFile.getValue();
    templateNameField.setText(templateFile == null ? StringUtils.EMPTY : templateFile.getName());
    applicationModel.templateFile.addListener((observable, oldValue, newValue) -> {
        templateNameField.setText(newValue == null ? StringUtils.EMPTY : newValue.getName());
    });//from w  ww . j  a va  2s . co  m
    return templateNameField;
}

From source file:ambroafb.general.mapeditor.MapEditor.java

public MapEditor() {
    this.setEditable(true);
    itemsMap = new HashMap<>();
    delimiter = " : "; // default value of delimiter
    keyPattern = ""; // (?<![\\d-])\\d+
    valuePattern = ""; // [0-9]{1,13}(\\.[0-9]*)?
    keySpecChars = "";
    valueSpecChars = "";

    this.setCellFactory((ListView<MapEditorElement> param) -> new CustomCell());

    removeElement = (MapEditorElement elem) -> {
        if (itemsMap.containsKey(elem.getKey())) {
            itemsMap.remove(elem.getKey());
            if (getValue() != null && getValue().compare(elem) == 0) {
                getEditor().setText(delimiter);
            }// w w  w  . j  a v a2 s.co  m
            getItems().remove(elem);
        }
    };

    editElement = (MapEditorElement elem) -> {
        getSelectionModel().select(-1);
        getEditor().setText(elem.getKey() + delimiter + elem.getValue());
        itemsMap.remove(elem.getKey());
        getItems().remove(elem);
    };

    // Never hide comboBox items listView:
    this.setSkin(new ComboBoxListViewSkin(this) {
        @Override
        protected boolean isHideOnClickEnabled() {
            return false;
        }
    });

    // Control textField input.
    TextField editor = getEditor();
    editor.setText(delimiter);
    editor.textProperty()
            .addListener((ObservableValue<? extends String> observable, String oldValue, String newValue) -> {
                if (newValue == null || newValue.isEmpty() || newValue.equals(delimiter)) {
                    editor.setText(delimiter);
                } else if (!newValue.contains(delimiter)) {
                    editor.setText(oldValue);
                } else {
                    String keyInput = StringUtils.substringBefore(newValue, delimiter).trim();
                    String valueInput = StringUtils.substringAfter(newValue, delimiter).trim();

                    if (!keyInput.isEmpty() && !Pattern.matches(keyPattern, keyInput)) {
                        keyInput = StringUtils.substringBefore(oldValue, delimiter).trim();
                    }
                    if (!valueInput.isEmpty() && !Pattern.matches(valuePattern, valueInput)) {
                        valueInput = StringUtils.substringAfter(oldValue, delimiter).trim();
                    }

                    editor.setText(keyInput + delimiter + valueInput);
                }
            });

    this.setConverter(new StringConverter<MapEditorElement>() {
        @Override
        public String toString(MapEditorElement object) {
            if (object == null) {
                return delimiter;
            }
            return object.getKey() + delimiter + object.getValue();
        }

        @Override
        public MapEditorElement fromString(String input) {
            MapEditorElement result = null;
            if (input != null && input.contains(delimiter)) {
                result = getNewInstance();
                if (result == null)
                    return null;
                String keyInput = StringUtils.substringBefore(input, delimiter).trim();
                String valueInput = StringUtils.substringAfter(input, delimiter).trim();
                if (!keyInput.isEmpty()) {
                    result.setKey(keyInput);
                }
                if (!valueInput.isEmpty()) {
                    result.setValue(valueInput);
                }
                boolean keyOutOfSpec = keySpecChars.isEmpty()
                        || !StringUtils.containsOnly(result.getKey(), keySpecChars);
                boolean valueOutOfSpec = valueSpecChars.isEmpty()
                        || !StringUtils.containsOnly(result.getValue(), valueSpecChars);
                if (!keyInput.isEmpty() && !valueInput.isEmpty() && !itemsMap.containsKey(keyInput)
                        && (keyOutOfSpec && valueOutOfSpec)) {
                    itemsMap.put(keyInput, result);
                    getItems().add(result);
                    return null;
                }
            }
            return result;
        }
    });

    // Control caret position in textField.
    editor.addEventFilter(KeyEvent.KEY_PRESSED, (KeyEvent event) -> {
        int caretOldPos = editor.getCaretPosition();
        int delimiterIndex = editor.getText().indexOf(delimiter);
        if (event.getCode().equals(KeyCode.RIGHT)) {
            if (caretOldPos + 1 > delimiterIndex && caretOldPos + 1 <= delimiterIndex + delimiter.length()) {
                editor.positionCaret(delimiterIndex + delimiter.length());
                event.consume();
            }
        } else if (event.getCode().equals(KeyCode.LEFT)) {
            if (caretOldPos - 1 >= delimiterIndex && caretOldPos - 1 < delimiterIndex + delimiter.length()) {
                editor.positionCaret(delimiterIndex);
                event.consume();
            }
        }
    });
}

From source file:com.loop81.fxcomparer.FXComparerController.java

private void handleFile(ComparableArchive archive, TextField filePath, Label infoLabel) {
    if (archive != null) {
        filePath.setText(archive.getPath());
        infoLabel.setText(MessageBundle.getString("file.info",
                FileUtils.byteCountToDisplaySize(archive.getSize()), archive.getSize()));

        if (archive1 != null && archive2 != null) {
            initCompare();//from  ww w.  j a va  2s. c o m
        }
    }
}

From source file:mesclasses.controller.PageController.java

public void markAsInteger(TextField field) {
    field.textProperty().addListener((observable, oldValue, newValue) -> {
        if (StringUtils.isBlank(newValue)) {
            return;
        }/*w w w . j av  a  2 s .  c o  m*/
        if (!StringUtils.isNumeric(newValue.substring(newValue.length() - 1))) {
            field.setText(newValue.substring(0, newValue.length() - 1));
        }
    });
}