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

[ComboBox] Popup not updated when items are added

    XMLWordPrintable

    Details

      Description

      See example below that demonstrates the issue which has the same reason as RT-15793 and is marked as temporarily fixed for comboBox as well.

          /**
           * - sanity: open popup and see it's empty (expected)
           * - press button
           * - open popup
           * - expected: see added item
           * - actual: empty
           */
          public class Combo15793Regression extends Application {
          
              @Override
              public void start(Stage primaryStage) throws Exception {
                  ComboBox box = new ComboBox();
                  Button button = new Button("set empty list and add item");
                  button.setOnAction(e -> {
                      box.setItems(FXCollections.observableArrayList());
                      box.getItems().add("Toto");
                  });
                  Parent root = new VBox(box, button);
                  primaryStage.setScene(new Scene(root));
                  primaryStage.setTitle(System.getProperty("java.version"));
                  primaryStage.show();
              }
          
              public static void main(String[] args) {
                  launch(args);
              }
          }

      Didn't try earlier versions to verify if it really worked for ComBox (the bug was reported against ListView), though the code looks like it should have:

          // FIXME temporary fix for RT-15793. This will need to be
          // properly fixed when time permits
          if (getSkin() instanceof ComboBoxListViewSkin) {
                ComboBoxListViewSkin<?> skin = (ComboBoxListViewSkin<?>) getSkin();
      //----> technically missing: skin.updateComboBoxItems();
      // which might have been added later than this hack
                skin.updateListViewItems();
           }

      culprit is the missing update of skin's alias to comboBoxItems

          public void updateListViewItems() {
             ...
              // sets list items to old comboBox items
              this.listViewItems = comboBoxItems;
              listView.setItems(listViewItems);
             ....
          }

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved:
              Imported: