java - JavaFX 2.0 Choice Box Issue. How to update a choiceBox, which represents a list of objects, when an object is updated? -


I have an option box that represents the list object. When the name representing one of those objects is replaced by the other bit code, the name does not change in the drop-down list for the option box. For example, if I have an option box that is made up of test objects, the code for the test is shown below:

  class test {string name; Public Test (string name) {this.name = name; } Public Zero Setname (string name) {this.name = name; } Public string getName () {return name; } @ Override public string to string () {return name; }}  

There is an option box next to:

  Choicebox & lt; Test & gt; CHE = New Choicebox & lt; & Gt; (); ObservableList & LT; Test & gt; Item = FXCollections.observableArrayList (); Chi.setItems (item); item. All (New Test ("ITEM1"), New Test ("ITEM2"), New Test ("ITEM3");  

Choicebox will show list ITEM1, ITEM2 and ITEM3

If I change the name of an item through the following code:

  Items.get (1) .setName ("Replace");  

Choicebox will still show the list ITEM1, ITEM2 and ITEM3. How can I create it so that the election box will show updates and list ITEM1, change and ITEM3?

Just for completeness - in Fx2 you are probably connected in the other way mentioned in the answer. Since Fax 8, the list has a mechanism to listen to changes in your inherent objects (of course, your item has properties and informs the audience on the change):

  / ** converted items * - Use property and notify on change * - Override to string (for visual, instead of using converter) * / square test {StringProperty name; Public Test (string name) {setName (name); } Public stringproperty nameproperty () {if (name == faucet) name = new string portapeti (this, "name"); Name of return; } Public Zero Setname (string name) {nameProperty (). Set (name); } Public string getName () {name name property (). Get (); }} // Extractor Observe List & lt; AlbumFx & gt; Use in the collection with. Item = FXCollections.observableList (E -> New Inspector [] {E.N.property ()}); Items.addAll (...); Choicebox = new choicebox & lt; & Gt; (item); // Tell this option that the item StringConverter & lt; Test & gt; Converter = new string connor & lt; Test & gt; () {@ Override public string tutorial (test album) {Return album! = Null? Album.getName (): Zero; } @ Override public test string (string string) {return tap; }}; ChoiceBox.setConverter (converter);  

Comments