Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8090015

ChoiceBox: must update value when setting a SelectionModel

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 8u20
    • javafx

      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());
          }

            jgiles Jonathan Giles
            fastegal Jeanette Winzenburg
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: