java binding choice box selected item property to a simple double property

240 Views Asked by At

I have double values inside of choice box, but how do I bind a choice box selected item property to a double property? The code below won't disable the button, as desired. It seems to me that it's because the selectedItemProperty is not an instanceof DoubleProperty? But I can't cast selectedItemProperty since it's a readonly property.. What should I do? Thank you very much in advance!

SimpleDoubleProperty valueToCheck = new SimpleDoubleProperty();
valueToCheck.set(314.1)
Button saveButton = new Button();
saveButton.disableProperty().bind(
        choiceBox.getSelectionModel().selectedItemProperty().isEqualTo(
                valueToCheck));
saveButton.setOnAction((ActionEvent event)->{
    valueToCheck.set((Double)choiceBox.getSelectionModel().getSelectedItem());
});
0

There are 0 best solutions below