private void checkEditorText() { IntegerSpinnerValueFactory valueFactory = getVF(); try { int value = Integer.parseInt(getEditor().getText()); int min = valueFactory.getMin(); int max = valueFactory.getMax(); value = Math.min(Math.max(min, value), max); getEditor().setText(String.valueOf(value)); valueFactory.setValue(value); } catch (NumberFormatException e) { getEditor().setText(String.valueOf(valueFactory.getValue())); } }
private void initFieldsAndValidation(ResourceBundle bundle) { // Setup input for name. validationSupport.registerValidator(txtName, false, new TextValidator(bundle.getString("dialog_create_user_error_name_required"), 255, false)); // Setup input for birthday. validationSupport.registerValidator(dateBirthday.getEditor(), false, new DateValidator(bundle.getString("dialog_create_user_error_birthday_invalid"), true)); // Setup input for height. spnHeight.setValueFactory(new IntegerSpinnerValueFactory(0, 9999, 0)); spnHeight.focusedProperty().addListener(new SpinnerFocusChangeListener<>(spnHeight)); validationSupport.registerValidator(spnHeight.getEditor(), false, new IntegerValidator(bundle.getString("dialog_create_user_error_height_invalid"), 0, 9999, true)); lblHeightUnit.setText(bundle.getString(heightUnitConverter.getUnit().getI18N())); // Register validation. validationSupport.invalidProperty().addListener((observable, oldValue, newValue) -> { getDialogPane().lookupButton(OK).setDisable(newValue); }); validationSupport.redecorate(); }
public void initialize() { super.initialize(); ////////////////////////////////////////////////////////////// spnFromIndex.setValueFactory(new IntegerSpinnerValueFactory(0, Integer.MAX_VALUE, 0)); spnToIndex.setValueFactory(new IntegerSpinnerValueFactory(Integer.MIN_VALUE, Integer.MAX_VALUE, 100)); Fx.fixIntegerSpinners(spnFromIndex, spnToIndex); ////////////////////////////////////////////////////////////// txtKey.setOnKeyPressed(event -> { if (event.getCode() == KeyCode.ENTER) { listValues(); } }); ////////////////////////////////////////////////////////////// // List key events lstValues.setOnKeyPressed(event -> { if (event.getCode() == KeyCode.C && event.isControlDown()) { // Ctrl+C listItemCopyClicked(); } else if (event.getCode() == KeyCode.DELETE) { // Delete deleteItem(); } }); // List mouse events lstValues.setOnMouseClicked(event -> { String value = lstValues.getSelectionModel().getSelectedItem(); if (event.getClickCount() == 2 && value != null) { editListItem(); } }); }
/** * Called by JavaFX. */ @Override public void initialize(URL url, ResourceBundle rb) { int min = 0; int max = 100; int initialValue = 0; qtySpinner.setValueFactory(new IntegerSpinnerValueFactory(min, max, initialValue)); qtySpinner.valueProperty().addListener( (obs, oldValue, newValue) -> { listController.updatePackageQty(this.packageData, newValue); } ); }
@Override public void initialize(URL url, ResourceBundle rb) { minCount.setEditable(true); minCount.setValueFactory(new IntegerSpinnerValueFactory(min, max,min)); minCount.valueProperty().addListener((observe, old, neo) -> update.run()); maxCount.setEditable(true); maxCount.setValueFactory(new IntegerSpinnerValueFactory(min, max,max)); maxCount.valueProperty().addListener((observe, old, neo) -> update.run()); }
@Test public void columnsSpinnerShouldBeBound(){ IntegerSpinnerValueFactory factory = ( IntegerSpinnerValueFactory )systemUnderTest.columnsSpinner().getValueFactory(); Assert.assertEquals( DimensionsPanel.MINIMUM_COLUMNS, factory.getMin() ); Assert.assertEquals( DimensionsPanel.MAXIMUM_COLUMNS, factory.getMax() ); }
@Before public void initialiseSystemUnderTest(){ TestApplication.startPlatform(); PlatformImpl.runAndWait( () -> { systemUnderTest = new IntegerPropertySpinner(); systemUnderTest.setValueFactory( new IntegerSpinnerValueFactory( 0, 100 ) ); } ); }
private void setUpSpinnerInt(Spinner<Integer> spinner, int pos, int min, int max, int increment, int savedSet ){ IntegerSpinnerValueFactory oswFactory = new SpinnerValueFactory.IntegerSpinnerValueFactory(min, max, savedSet, increment); spinner.setValueFactory(oswFactory); spinner.valueProperty().addListener((obs, oldValue, newValue) -> { System.out.println("New value: "+newValue); // hier könnte es rundungsfehler von double auf Number geben setValueSettings(pos, newValue); }); }
/** * Creates the {@link ComboBox} used for selection a year. * * @return the {@link ComboBox} for selecting a year. */ private Spinner<Integer> createYearSelector() { Spinner<Integer> yearSpinner = new FXSpinnerRT40623<>(new IntegerSpinnerValueFactory(Integer.MIN_VALUE, Integer.MAX_VALUE)); yearSpinner.getStyleClass().add("year-selector"); yearSpinner.setEditable(true); yearSpinner.valueProperty().addListener(this::onSelectedYearChanged); return yearSpinner; }
private static void setSpinnerBehaviour( final IntegerSpinnerValueFactory svf, final boolean useDefaultValue, final ObservableIntegerValue defaultValue, final ObjectProperty<Integer> customValue ) { if (useDefaultValue) { svf.valueProperty().unbindBidirectional(customValue); svf.setValue(defaultValue.get()); } else { svf.setValue(customValue.getValue()); svf.valueProperty().bindBidirectional(customValue); } }
public TimeRangeFieldSkin(TimeRangeField control) { super(control); ComboBox<TimeRangeField.TimeRangeFieldValue> valuesComboBox = new ComboBox<>(); valuesComboBox.setConverter(new TimeRangeFieldValueStringConverter()); valuesComboBox.setItems(control.getValues()); valuesComboBox.valueProperty().bindBidirectional(control.valueProperty()); valuesComboBox.setVisibleRowCount(5); datePicker = new DatePicker(); datePicker.getEditor().setPrefColumnCount(6); datePicker.valueProperty().bindBidirectional(control.onDateProperty()); datePicker.managedProperty().bind(datePicker.visibleProperty()); datePicker.setEditable(false); weekValueFactory = new IntegerSpinnerValueFactory(1, 52); weekValueFactory.valueProperty().addListener(obs -> control.setOnWeekNumber(weekValueFactory.getValue())); control.onWeekNumberProperty().addListener(obs -> { if (control.getOnWeekNumber() != null) { weekValueFactory.setValue(control.getOnWeekNumber()); } }); weekNumberSpinner = new Spinner<>(); weekNumberSpinner.setValueFactory(weekValueFactory); weekNumberSpinner.managedProperty().bind(weekNumberSpinner.visibleProperty()); weekNumberSpinner.setPrefWidth(70); monthYearValueFactory = new IntegerSpinnerValueFactory(1972, 3000); monthYearValueFactory.valueProperty().addListener(obs -> control.setMonthYear(monthYearValueFactory.getValue())); control.monthYearProperty().addListener(obs -> { if (control.getMonthYear() != null) { monthYearValueFactory.setValue(control.getMonthYear()); } }); monthYearSpinner = new Spinner<>(); monthYearSpinner.getEditor().setPrefColumnCount(6); monthYearSpinner.setValueFactory(monthYearValueFactory); monthYearSpinner.managedProperty().bind(monthYearSpinner.visibleProperty()); afterUnitsValueFactory = new IntegerSpinnerValueFactory(1, 500); afterUnitsValueFactory.valueProperty().addListener(obs -> control.setAfterUnits(afterUnitsValueFactory.getValue())); control.afterUnitsProperty().addListener(obs -> { if (control.getAfterUnits() != null) { afterUnitsValueFactory.setValue(control.getAfterUnits()); } }); afterUnitsSpinner = new Spinner<>(); afterUnitsSpinner.getEditor().setPrefColumnCount(4); afterUnitsSpinner.setValueFactory(afterUnitsValueFactory); afterUnitsSpinner.managedProperty().bind(afterUnitsSpinner.visibleProperty()); afterUnitsLabel = new Label(); afterUnitsLabel.managedProperty().bind(afterUnitsLabel.visibleProperty()); InvalidationListener listener = obs -> layout(); control.viewTypeProperty().addListener(listener); control.valueProperty().addListener(listener); HBox container = new HBox(5, valuesComboBox, datePicker, weekNumberSpinner, monthYearSpinner, afterUnitsSpinner, afterUnitsLabel); container.setAlignment(Pos.CENTER_LEFT); HBox.setHgrow(valuesComboBox, Priority.ALWAYS); HBox.setHgrow(datePicker, Priority.SOMETIMES); getChildren().add(container); layout(); }
private IntegerSpinnerValueFactory getVF() { return (IntegerSpinnerValueFactory) getValueFactory(); }
private void configureIntegerSpinner(Spinner<Integer> spinner, Property<Integer> prop, int min, int max) { IntegerSpinnerValueFactory factory = new IntegerSpinnerValueFactory(min, max); factory.valueProperty().bindBidirectional(prop); spinner.setValueFactory(factory); }
public IntegerControl(Options o, IntegerSetting setting) { setSpacing(3); // Option Name Label title = new Label(setting.getHumanName()); title.getStyleClass().add("title"); title.setFont(new Font(20)); getChildren().add(title); // Option Desc if (!setting.getDescription().equals("")) { Label desc = new Label(setting.getDescription()); desc.getStyleClass().add("description"); desc.setFont(new Font(14)); desc.setWrapText(true); getChildren().add(desc); } // Option Value Spinner<Integer> value = new Spinner<>(); IntegerSpinnerValueFactory factory = new IntegerSpinnerValueFactory(0, 0); factory.setMax(setting.getHighBound()); factory.setMin(setting.getLowBound()); factory.setValue(setting.getValue()); value.setValueFactory(factory); value.setEditable(true); value.getStyleClass().add("value"); value.setPrefWidth(Double.MAX_VALUE); value.valueProperty().addListener(e -> { if (setting.isValid(value.getValue())) { o.madeChanges(); setting.setValue(value.getValue()); } else value.getValueFactory().setValue(setting.getValue()); }); getChildren().add(value); // Tooltip // Tooltip tooltip = new Tooltip(setting.getDescription()); // Tooltip.install(title, tooltip); // Tooltip.install(value, tooltip); }