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

ComboBox: becomes unclickable after removal and re-adding

XMLWordPrintable

    • b15

      To reproduce, compile and run

      - open dropdown with mouse and select an item: this will remove the combo and re-add it to the parent
      - click on re-added combo
      - expected: dropdown opened
      - actual: nothing happens

      This seems to happen if the combo is removed while the dropdown is open. Indicators for that assumption:
      a) select item by keyboard without opening -> behaves as expected
      b) explicitly hide the combo before removal (in the listener) -> behaves as expected

      Similar issue as JDK-8095306 which was fixed to handle the initial showing, but not the dynamic case. So the fix for this should be along those line, f.i. in skin's constructor, install a in a listener to the combo's scene property, which keeps combo's showing in sync with popup's showing

          registerChangeListener(combo.sceneProperty(), e -> {
              if (combo.getScene() == null) {
                  // arguable:
                  // on removal, the popup is hidden,
                  // force combo to hide also
                  combo.hide();
              } else if (combo.isShowing()) {
                  // ensure popup is showing
                  show();
              }
          });

      Also, check DatePickerSkin and any other sub of ComboPopupControl if they have similar issues (initial and dynamic).

      Code example (from SO https://stackoverflow.com/q/48538763/203657):

      public class ComboBoxTest extends Application {

          public static void main(String[] args) {
              ComboBoxTest.launch(args);
          }

          @Override
          public void start(Stage stage) {
              VBox root = new VBox();

              final ComboBox<String> choices = new ComboBox<>();
              choices.getItems().add("Test1");
              choices.getItems().add("Test2");
              root.getChildren().add(choices);

              choices.getSelectionModel().selectedItemProperty().addListener(
                  (observable, oldValue, newValue) -> {
                      root.getChildren().clear();
                      root.getChildren().add(choices);
              });

              Platform.setImplicitExit(true);
              stage.setScene(new Scene(root));
              stage.show();
          }
      }

            arapte Ambarish Rapte
            fastegal Jeanette Winzenburg
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: