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

The following examples show how to use javafx.scene.control.Spinner#setValueFactory() . 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: SpinnerSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
private Spinner<Object> createListSpinner() {
    Spinner<Object> spinner = new Spinner<>();
    spinner.setId("list-spinner");
    List<Object> names = new ArrayList<Object>();
    names.add("January");
    names.add("February");
    names.add("March");
    names.add("April");
    names.add("May");
    names.add("June");
    names.add("July");
    names.add("August");
    names.add("September");
    names.add("October");
    names.add("November");
    names.add("December");
    spinner.setValueFactory(new SpinnerValueFactory.ListSpinnerValueFactory<Object>(FXCollections.observableArrayList(names)));
    return spinner;
}
 
Example 2
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 3
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 4
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 5
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 6
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 7
Source File: SpinnerSample.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
private Spinner<Integer> createIntegerSpinner() {
    Spinner<Integer> spinner = new Spinner<>();
    spinner.setId("integer-spinner");
    spinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 50));
    return spinner;
}
 
Example 8
Source File: SpinnerRepresentation.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected final Spinner<String> createJFXNode() throws Exception
{
    final Spinner<String> spinner = new Spinner<>();
    spinner.setValueFactory(createSVF());
    styleChanged(null, null, null);
    spinner.setMinSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
    spinner.focusedProperty().addListener((property, oldval, newval)->
    {
        if (!spinner.isFocused())
            restore();
        active = false;
    });
    spinner.getEditor().setOnKeyPressed((final KeyEvent event) ->
    {
        switch (event.getCode())
        {
        case ESCAPE: //TODO: fix: escape key event not sensed
            // Revert original value, leave active state
            restore();
            active = false;
            break;
        case ENTER:
            // Submit value, leave active state
            submit();
            active = false;
            break;
        //incrementing by keyboard
        case UP:
        case PAGE_UP:
            if (!active)
                jfx_node.getValueFactory().increment(1);
            break;
        case DOWN:
        case PAGE_DOWN:
            if (!active)
                jfx_node.getValueFactory().decrement(1);
            break;
        default:
            // Any other key results in active state
            active = true;
        }
    });

    // Disable the contemporary triggering of a value change and of the
    // opening of contextual menu when right-clicking on the spinner's
    // buttons.
    spinner.addEventFilter(MouseEvent.ANY, e ->
    {
        if (e.getButton() == MouseButton.SECONDARY)
            e.consume();
    });

    // This code manages layout,
    // because otherwise for example border changes would trigger
    // expensive Node.notifyParentOfBoundsChange() recursing up the scene graph
    spinner.setManaged(false);

    return spinner;
}