Java Code Examples for javafx.scene.control.Spinner#setEditable()

The following examples show how to use javafx.scene.control.Spinner#setEditable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ValidatorUtils.java    From kafka-message-tool with MIT License 5 votes vote down vote up
public static void configureSpinner(Spinner<Integer> spinner, IntegerProperty referenceProperty, int minValue, int maxValue) {
    spinner.setEditable(true);
    spinner.setTooltip(TooltipCreator.createFrom("Max value: " + maxValue));
    spinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(minValue,
                                                                               Integer.MAX_VALUE,
                                                                               referenceProperty.get()));
    GuiUtils.configureTextFieldToAcceptOnlyValidData(spinner.getEditor(),
                                                     stringConsumer(referenceProperty),
                                                     validationFunc(maxValue));
    configureTextFieldToAcceptOnlyDecimalValues(spinner.getEditor());
}
 
Example 2
Source File: SpinnerSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private Spinner<Double> createDoubleSpinner() {
    Spinner<Double> spinner = new Spinner<Double>();
    spinner.setId("double-spinner");
    spinner.setValueFactory(new SpinnerValueFactory.DoubleSpinnerValueFactory(25.50, 50.50));
    spinner.setEditable(true);
    return spinner;
}
 
Example 3
Source File: SpinnerDemo.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void start(final Stage stage)
{
    final Label label = new Label("Demo:");

    SpinnerValueFactory<Double> svf = new SpinnerValueFactory.DoubleSpinnerValueFactory(0, 1000);
    Spinner<Double> spinner = new Spinner<>();
    spinner.setValueFactory(svf);
    spinner.editorProperty().getValue().setStyle("-fx-text-fill:" + "black");
    spinner.editorProperty().getValue().setBackground(
            new Background(new BackgroundFill(Color.AZURE, CornerRadii.EMPTY, Insets.EMPTY)));


    //spinner.getStyleClass().add(Spinner.STYLE_CLASS_ARROWS_ON_LEFT_VERTICAL);
    //int x = spinner.getStyleClass().indexOf(Spinner.STYLE_CLASS_ARROWS_ON_LEFT_VERTICAL);
    //if (x > 0) spinner.getStyleClass().remove(x);

    spinner.setEditable(true);
    spinner.setPrefWidth(80);

    spinner.valueProperty().addListener((prop, old, value) ->
    {
        System.out.println("Value: " + value);
    });

    final HBox root = new HBox(label, spinner);

    final Scene scene = new Scene(root, 800, 700);
    stage.setScene(scene);
    stage.setTitle("Spinner Demo");

    stage.show();
}
 
Example 4
Source File: DateTimePane.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private static Spinner<Integer> createSpinner(final int max, final Spinner<Integer> next)
{
    final Spinner<Integer> spinner = new Spinner<>(0, max, 0);
    spinner.getStyleClass().add(Spinner.STYLE_CLASS_SPLIT_ARROWS_VERTICAL);
    spinner.setEditable(true);
    spinner.setValueFactory(new WraparoundValueFactory(0, max, next == null ? null : next.getValueFactory()));
    spinner.getValueFactory().setConverter(WraparoundValueFactory.TwoDigitStringConverter);
    spinner.setPrefWidth(45);
    return spinner;
}
 
Example 5
Source File: TemporalAmountPane.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private static Spinner<Integer> createSpinner(final int max, final Spinner<Integer> next)
{
    final Spinner<Integer> spinner = new Spinner<>(0, max, 0);
    spinner.setEditable(true);
    spinner.setValueFactory(new WraparoundValueFactory(0, max, next == null ? null : next.getValueFactory()));
    spinner.getValueFactory().setConverter(WraparoundValueFactory.TwoDigitStringConverter);
    spinner.getValueFactory().setValue(0);
    spinner.setPrefWidth(65);
    return spinner;
}
 
Example 6
Source File: DateTimeRangeInputPane.java    From constellation with Apache License 2.0 4 votes vote down vote up
/**
 * Build the hour/minute/second part of the datetime picker.
 *
 * @param label
 * @param min
 * @param max
 * @param value
 * @param changed
 * @return
 */
private Pane createSpinner(final String label, final int min, final int max, final ChangeListener<String> changed) {
    final int NUMBER_SPINNER_WIDTH = 55;
    final String small = "-fx-font-size: 75%;";

    final Spinner<Integer> spinner = new Spinner<>(min, max, 1);
    spinner.setPrefWidth(NUMBER_SPINNER_WIDTH);

    // Create a filter to limit text entry to just numerical digits
    final NumberFormat format = NumberFormat.getIntegerInstance();
    final UnaryOperator<TextFormatter.Change> filter = c -> {
        if (c.isContentChange()) {
            final ParsePosition parsePosition = new ParsePosition(0);
            // NumberFormat evaluates the beginning of the text
            format.parse(c.getControlNewText(), parsePosition);
            if (parsePosition.getIndex() == 0 || c.getControlNewText().length() > 2
                    || parsePosition.getIndex() < c.getControlNewText().length()) {
                // reject parsing the complete text failed
                return null;
            }
        }
        return c;
    };

    // Ensure spinner is set to editable, meaning user can directly edit text, then hook in
    // a text formatter which in turn will trigger flitering of input text.
    spinner.setEditable(true);
    final TextFormatter<Integer> timeFormatter = new TextFormatter<>(new IntegerStringConverter(), 0, filter);
    spinner.getEditor().setTextFormatter(timeFormatter);

    final Label spinnerLabel = new Label(label);
    spinnerLabel.setLabelFor(spinner);
    spinnerLabel.setStyle(small);

    final VBox vbox = new VBox();
    vbox.getChildren().addAll(spinnerLabel, spinner);

    spinner.valueProperty().addListener((ObservableValue<? extends Number> observable, Number oldValue, Number newValue) -> {
        changed.changed(null, null, null);
    });

    timeSpinners.add(spinner);

    return vbox;
}