I have a Box selection that represents list objects. When a name representing one of these objects is changed by another bit of code, the name in the drop-down list for the selection field does not change. For example, if I have a selection box consisting of a list of Test objects. The code for testing is shown below:
class Test { String name; public Test(String name) { this.name = name; } public void setName(String name) { this.name = name; } public String getName() { return name; } @Override public String toString() { return name; } }
Then you have the Box selection as follows:
ChoiceBox<Test> chi = new ChoiceBox<>(); ObservableList<Test> items = FXCollections.observableArrayList(); chi.setItems(items); items.addAll(new Test("ITEM1"),new Test("ITEM2"),new Test("ITEM3"));
ChoiceBox will show list of ITEM1, ITEM2 and ITEM3
If I then changed the name of one of the elements with the following code:
items.get(1).setName("CHANGED");
ChoiceBox will still show a list of ITEM1, ITEM2 and ITEM3. How can I make selectBox update and display a list of ITEM1, CHANGED and ITEM3?
source share