Example usage for javafx.scene.control TextField textProperty

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

Introduction

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

Prototype

public final StringProperty textProperty() 

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;
        }//  w w  w.  j a  v a2 s  .  co  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  w w  w .  j  a va2 s. com*/
        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 2s  .c om
        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 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);
        }// w  w  w .ja v a  2 s . co m
    });

    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:mesclasses.controller.PageController.java

public final void markAsMandatory(TextField field) {
    field.textProperty().addListener((observable, oldValue, newValue) -> {
        checkMandatory(field);//w w w . j a  v  a 2 s.c  om
    });
}

From source file:mesclasses.controller.PageController.java

public void markAsUnique(TextField field) {
    field.textProperty().addListener((observable, oldValue, newValue) -> {
        if (!isUnique(newValue)) {
            addUnicityError(field);//from  w w  w  . j  ava 2  s . co  m
        } else {
            removeUnicityError(field);
        }
    });
}

From source file:mesclasses.controller.PageController.java

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

From source file:eu.over9000.skadi.ui.dialogs.PerformUpdateDialog.java

public PerformUpdateDialog(RemoteVersionResult newVersion) {
    this.chosen = new SimpleObjectProperty<>(
            Paths.get(SystemUtils.USER_HOME, newVersion.getVersion() + ".jar").toFile());

    this.setHeaderText("Updating to " + newVersion.getVersion());
    this.setTitle("Skadi Updater");
    this.getDialogPane().getStyleClass().add("alert");
    this.getDialogPane().getStyleClass().add("information");

    final ButtonType restartButtonType = new ButtonType("Start New Version", ButtonBar.ButtonData.OK_DONE);
    this.getDialogPane().getButtonTypes().addAll(restartButtonType, ButtonType.CANCEL);

    Node btn = this.getDialogPane().lookupButton(restartButtonType);
    btn.setDisable(true);//from w w w . j  av  a 2  s . c o  m

    Label lbPath = new Label("Save as");
    TextField tfPath = new TextField();
    tfPath.textProperty()
            .bind(Bindings.createStringBinding(() -> this.chosen.get().getAbsolutePath(), this.chosen));
    tfPath.setPrefColumnCount(40);
    tfPath.setEditable(false);

    Button btChangePath = GlyphsDude.createIconButton(FontAwesomeIcons.FOLDER_OPEN, "Browse...");
    btChangePath.setOnAction(event -> {
        FileChooser fc = new FileChooser();
        fc.setTitle("Save downloaded jar..");
        fc.setInitialFileName(this.chosen.getValue().getName());
        fc.getExtensionFilters().add(new FileChooser.ExtensionFilter("Jar File", ".jar"));
        fc.setInitialDirectory(this.chosen.getValue().getParentFile());
        File selected = fc.showSaveDialog(this.getOwner());
        if (selected != null) {
            this.chosen.set(selected);
        }
    });

    ProgressBar pbDownload = new ProgressBar(0);
    pbDownload.setDisable(true);
    pbDownload.setMaxWidth(Double.MAX_VALUE);
    Label lbDownload = new Label("Download");
    Label lbDownloadValue = new Label();
    Button btDownload = GlyphsDude.createIconButton(FontAwesomeIcons.DOWNLOAD, "Start");
    btDownload.setMaxWidth(Double.MAX_VALUE);
    btDownload.setOnAction(event -> {
        btChangePath.setDisable(true);
        btDownload.setDisable(true);

        this.downloadService = new DownloadService(newVersion.getDownloadURL(), this.chosen.getValue());

        lbDownloadValue.textProperty().bind(this.downloadService.messageProperty());
        pbDownload.progressProperty().bind(this.downloadService.progressProperty());

        this.downloadService.setOnSucceeded(dlEvent -> {
            btn.setDisable(false);
        });
        this.downloadService.setOnFailed(dlFailed -> {
            LOGGER.error("new version download failed", dlFailed.getSource().getException());
            lbDownloadValue.textProperty().unbind();
            lbDownloadValue.setText("Download failed, check log file for details.");
        });

        this.downloadService.start();
    });

    final GridPane grid = new GridPane();
    grid.setHgap(10);
    grid.setVgap(10);

    grid.add(lbPath, 0, 0);
    grid.add(tfPath, 1, 0);
    grid.add(btChangePath, 2, 0);
    grid.add(new Separator(), 0, 1, 3, 1);
    grid.add(lbDownload, 0, 2);
    grid.add(pbDownload, 1, 2);
    grid.add(btDownload, 2, 2);
    grid.add(lbDownloadValue, 1, 3);

    this.getDialogPane().setContent(grid);

    this.setResultConverter(btnType -> {
        if (btnType == restartButtonType) {
            return this.chosen.getValue();
        }

        if (btnType == ButtonType.CANCEL) {
            if (this.downloadService.isRunning()) {
                this.downloadService.cancel();
            }
        }

        return null;
    });

}

From source file:com.rcs.shoe.shop.fx.controller.ui.NewProductController.java

private void initializeQuantityFields() {
    quantityFields = new HashMap<>();
    quantityLabels = new HashMap<>();
    ObservableList<Node> children = sizesPane.getChildren();
    for (Node node : children) {
        if (node instanceof TextField) {
            TextField tx = (TextField) node;
            tx.textProperty().addListener(getDigitChangeListener(tx));
            quantityFields.put(tx.getId(), tx);
        } else if (node instanceof Label) {
            Label label = (Label) node;
            if (label.getId() != null && label.getId().startsWith("label")) {
                quantityLabels.put(label.getId(), label);
            }/*from  w  w  w .ja  va  2  s.  co  m*/
        }
    }
}

From source file:com.rcs.shoe.shop.fx.controller.ui.Controller.java

protected ChangeListener getDigitChangeListener(final TextField textField) {
    ChangeListener<String> result = new ChangeListener<String>() {
        @Override//from  w w w . j ava 2  s .  c  o m
        public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
            if (StringUtils.isBlank(newValue)) {
                textField.textProperty().setValue("");
            } else if (NumberUtils.isDigits(newValue)) {
                textField.textProperty().setValue(newValue);
            } else {
                textField.textProperty().setValue(oldValue);
            }
        }
    };
    return result;
}