3 Replies Latest reply: Nov 7, 2013 10:11 AM by drenda81 RSS

    ComboBox and bidirectional binding

    987995
      Hi,

      I implement a ComboBox where I load an ArrayList of Enums into it by using

      this.getItems().addAll(getMYEnumEntries());

      Within the enum I override the toString method, so all the items are displayed correct in my ComboBox .

      My problem is, that I use JavaFX bidirectional binding ... and I find now snippet how to use it correct.

      * My first question is...to which property must I bind the bean to the combobox that I get informed aboud a change of the value?

      * My second questiion is...how must I implement the my Property Binding Class ?? Can I use the SimpleObjectProperty and override getValue() ... setValue() ?

      best regards
      wolfgang

      Edited by: wschele on 14.04.2013 00:28
        • 1. Re: ComboBox and bidirectional binding
          shakir.gusaroff
          You can not use a bidirectional binding with ComboBox properties because the following properties are read-only:
           comboBox.getSelectionModel().selectedItemProperty()
           comboBox.getSelectionModel().selectedIndexProperty()
          You can bind to or add a listener to those properties.
          • 2. Re: ComboBox and bidirectional binding
            987995
            Hi,

            I solved it by using the valueProperty ... instead the model based props...

            myComboBox.valueProperty().addListener(new ChangeListener<String>() ..

            I wrote an own binder and extended my framework with it...

            thx
            wschele
            • 3. Re: ComboBox and bidirectional binding
              drenda81

              Hi guys,

              I'm figthing with this problem.

               

              I've some Combobox to which I'm making bidirectional binding. In ComboBox<String> and ComboBox<Enum> all works fine, but in ComboBox<Object> bidirectional binding doesn't work.

               

              Hi don't understand why....I read the fact that selectedItemProperty() is read only but why with ComboBox<String> or ComboBox<Enum> it works??

               

              Thanks