本文整理汇总了Java中javafx.scene.control.Spinner.setValueFactory方法的典型用法代码示例。如果您正苦于以下问题:Java Spinner.setValueFactory方法的具体用法?Java Spinner.setValueFactory怎么用?Java Spinner.setValueFactory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.control.Spinner
的用法示例。
在下文中一共展示了Spinner.setValueFactory方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createListSpinner
import javafx.scene.control.Spinner; //导入方法依赖的package包/类
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;
}
示例2: createDoubleSpinner
import javafx.scene.control.Spinner; //导入方法依赖的package包/类
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;
}
示例3: initializeSpinner
import javafx.scene.control.Spinner; //导入方法依赖的package包/类
public static void initializeSpinner(final Spinner<Integer> spinner, final int minValue, final int maxValue, final int initialValue) {
spinner.getEditor().setOnKeyPressed(event -> {
switch (event.getCode()) {
case UP:
spinner.increment(1);
break;
case DOWN:
spinner.decrement(1);
break;
}
});
spinner.setOnScroll(e -> {
spinner.increment((int) (e.getDeltaY() / e.getMultiplierY()));
});
SpinnerValueFactory<Integer> factory = new SpinnerValueFactory.IntegerSpinnerValueFactory(minValue, maxValue, initialValue);
spinner.setValueFactory(factory);
spinner.setEditable(true);
TextFormatter<Integer> formatter = new TextFormatter<>(factory.getConverter(), factory.getValue());
spinner.getEditor().setTextFormatter(formatter);
factory.valueProperty().bindBidirectional(formatter.valueProperty());
}
示例4: setSpinnerValueFactory
import javafx.scene.control.Spinner; //导入方法依赖的package包/类
public void setSpinnerValueFactory(final Spinner _spinner, final String _newValue) {
ObservableList<String> items = FXCollections.observableArrayList("Jonathan", "Julia", "Henry");
switch (_newValue) {
case "Integer": {
_spinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(5, 10));
break;
}
case "List<String>": {
_spinner.setValueFactory(new SpinnerValueFactory.ListSpinnerValueFactory<>(items));
break;
}
/* postponed. see https://javafx-jira.kenai.com/browse/RT-37968
case "Calendar": {
_spinner.setValueFactory(new SpinnerValueFactory.LocalDateSpinnerValueFactory());
break;
}
*/
case "Double": {
_spinner.setValueFactory(new SpinnerValueFactory.DoubleSpinnerValueFactory(0.0, 1.0, 0.5, 0.05));
break;
}
default: {
_spinner.setValueFactory(null);
break;
}
}
}
示例5: DoubleControl
import javafx.scene.control.Spinner; //导入方法依赖的package包/类
public DoubleControl(Options o, DoubleSetting setting) {
setSpacing(3);
// Option Name
Label title = new Label(setting.getHumanName());
title.setFont(new Font(20));
title.getStyleClass().add("title");
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<Double> value = new Spinner<>();
DoubleSpinnerValueFactory factory = new DoubleSpinnerValueFactory(0, 0);
factory.setMax(setting.getHighBound());
factory.setMin(setting.getLowBound());
factory.setValue(setting.getValue());
double step = (setting.getHighBound() - setting.getLowBound()) / 1000;
factory.setAmountToStepBy(step <= 20 ? step : 20);
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);
}
示例6: setUpSpinnerInt
import javafx.scene.control.Spinner; //导入方法依赖的package包/类
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);
});
}
示例7: setUpSpinnerDouble
import javafx.scene.control.Spinner; //导入方法依赖的package包/类
private void setUpSpinnerDouble(Spinner<Double> spinner, int pos, double min, double max, double increment, double savedSet){
DoubleSpinnerValueFactory oswFactory = new SpinnerValueFactory.DoubleSpinnerValueFactory(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);
});
}
示例8: start
import javafx.scene.control.Spinner; //导入方法依赖的package包/类
@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();
}
示例9: addSpinnerAndButton
import javafx.scene.control.Spinner; //导入方法依赖的package包/类
private void addSpinnerAndButton() {
List<String> propertyTypeList = new ArrayList<String>();
propertyTypeList.add("String");
propertyTypeList.add("Number");
propertyTypeList.add("Date");
propertyTypeList.add("Pointset");
ObservableList<String> obsPropTypeList = FXCollections.observableList(propertyTypeList);
SpinnerValueFactory<String> svf = new SpinnerValueFactory.ListSpinnerValueFactory<>(obsPropTypeList);
Spinner<String> propertyTypeSpinner = new Spinner<String>();
propertyTypeSpinner.setValueFactory(svf);
Button deleteRowButton = new Button("x");
HBox spinnerAndButtonBox = new HBox();
spinnerAndButtonBox.setAlignment(Pos.CENTER_RIGHT);
HBox.setHgrow(spinnerAndButtonBox, Priority.ALWAYS);
spinnerAndButtonBox.getChildren().addAll(propertyTypeSpinner, deleteRowButton);
unmatchedPropertyBox.getChildren().add(spinnerAndButtonBox);
unmatchedPropertyBox.setAlignment(Pos.CENTER_LEFT);
unmatchedPropertyBox.setPrefWidth(stage.getWidth());
deleteRowButton.setOnAction(e_ -> {
HBox column = (HBox) deleteRowButton.getParent();
String matchedSource = ((Label) ((VBox) column.getChildren().get(0)).getChildren().get(0)).getText();
String matchedTarget = ((Label) ((VBox) column.getChildren().get(1)).getChildren().get(0)).getText();
if (matchedSource != null) {
sourcePropList.getItems().add(matchedSource);
}
if (matchedTarget != null) {
targetPropList.getItems().add(matchedTarget);
}
VBox row = (VBox) deleteRowButton.getParent().getParent();
row.getChildren().remove(deleteRowButton.getParent());
});
}
示例10: createIntegerSpinner
import javafx.scene.control.Spinner; //导入方法依赖的package包/类
private Spinner<Integer> createIntegerSpinner() {
Spinner<Integer> spinner = new Spinner<>();
spinner.setId("integer-spinner");
spinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 50));
return spinner;
}
示例11: configureIntegerSpinner
import javafx.scene.control.Spinner; //导入方法依赖的package包/类
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);
}
示例12: configureDoubleSpinner
import javafx.scene.control.Spinner; //导入方法依赖的package包/类
private void configureDoubleSpinner(Spinner<Double> spinner, Property<Double> prop, double min, double max) {
DoubleSpinnerValueFactory factory = new DoubleSpinnerValueFactory(min, max);
factory.valueProperty().bindBidirectional(prop);
spinner.setValueFactory(factory);
}
示例13: IntegerControl
import javafx.scene.control.Spinner; //导入方法依赖的package包/类
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);
}
示例14: createJFXNode
import javafx.scene.control.Spinner; //导入方法依赖的package包/类
@Override
protected final Spinner<String> createJFXNode() throws Exception
{
final Spinner<String> spinner = new Spinner<String>();
spinner.setValueFactory(createSVF());
styleChanged(null, null, null);
spinner.setMinSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
if (!toolkit.isEditMode())
spinner.setEditable(true);
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;
}
});
return spinner;
}