如何在 FXML 中双向绑定滑块

How to bi-directionally bind slider in FXML

我在 FXML 中定义了一个 Slider

<Slider fx:id="sldThreshold" blockIncrement="10.0" majorTickUnit="10.0" max="255.0" min="0"
    minorTickCount="1" prefWidth="600.0" showTickLabels="true" showTickMarks="true"
    snapToTicks="true" />

我在 POJO class Settings.java(不是控制器!)中定义了一个 SimpleIntegerProperty,其中包含 getter、setter 和 属性-getter.

private static final SimpleIntegerProperty threshold = new SimpleIntegerProperty(10);

public static SimpleIntegerProperty thresholdProperty() {
    return threshold;
}

public static Integer getThreshold() {
    return threshold.getValue();
}

public static void setThreshold(int threshold){
    threshold.set(threshold);
}

我看过一些示例如何在控制器中的 java 代码中绑定它,但没有提及如何在 FXML 声明中进行绑定。

您不能在 FXML 中进行双向绑定。在控制器中进行绑定。