-
Bug
-
Resolution: Fixed
-
P4
-
8u20
value property is doc'ed to always be synched to the selectedItem of the selection model. That synch is broken when setting a SelectionModel that has a selectedItem. Either the box itself or its skin (or maybe both) is broken in not updating the value.
/**
* Standalone test: setting a selectionModel which has a selected item
* must update the value
*/
@Test
public void testSetSelectionModelUpdatesValueStandalone() {
ObservableList<String> items = FXCollections.observableArrayList(
"9-item", "8-item", "7-item", "6-item",
"5-item", "4-item", "3-item", "2-item", "1-item");
ChoiceBox box = new ChoiceBox(items);
SingleSelectionModel model = new SingleSelectionModel() {
@Override
protected Object getModelItem(int index) {
if (index < 0 || index >= getItemCount()) return null;
return box.getItems().get(index);
}
@Override
protected int getItemCount() {
return box.getItems() != null ? box.getItems().size() : 0;
}
};
// just to be on the safe side in case the skin/behaviour is
// responsible for the update
// doesn't make a difference, though
StageLoader loader = new StageLoader(box);
int index = 2;
model.select(index);
assertEquals("sanity: model is selecting index and item", items.get(index),
model.getSelectedItem());
box.setSelectionModel(model);
assertEquals("box value must be same as selected item", items.get(index), box.getValue());
}
/**
* Standalone test: setting a selectionModel which has a selected item
* must update the value
*/
@Test
public void testSetSelectionModelUpdatesValueStandalone() {
ObservableList<String> items = FXCollections.observableArrayList(
"9-item", "8-item", "7-item", "6-item",
"5-item", "4-item", "3-item", "2-item", "1-item");
ChoiceBox box = new ChoiceBox(items);
SingleSelectionModel model = new SingleSelectionModel() {
@Override
protected Object getModelItem(int index) {
if (index < 0 || index >= getItemCount()) return null;
return box.getItems().get(index);
}
@Override
protected int getItemCount() {
return box.getItems() != null ? box.getItems().size() : 0;
}
};
// just to be on the safe side in case the skin/behaviour is
// responsible for the update
// doesn't make a difference, though
StageLoader loader = new StageLoader(box);
int index = 2;
model.select(index);
assertEquals("sanity: model is selecting index and item", items.get(index),
model.getSelectedItem());
box.setSelectionModel(model);
assertEquals("box value must be same as selected item", items.get(index), box.getValue());
}
- relates to
-
JDK-8242001 ChoiceBox: must update value on setting SelectionModel, part 2
-
- Resolved
-