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

ComboBox popup not closing on selection if last item was initial selected

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      Since JavaFX 19 the popup of ComboBoxes don't close anymore when the selection changes. This behavior can be tracked down to the introduction of the focusWithin-Property.

      REGRESSION : Last worked in version 17

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) ComboBox with a number of items
      2) Last item is initally selected
      3) Open ComboBox with mouse or keyboard
      4) Select different entry

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Popup of ComboBox closes
      ACTUAL -
      Popup of ComboBox remains opened

      ---------- BEGIN SOURCE ----------
      public class BugReproduce_L15_61028 extends Application {

          @Override
          public void start(Stage primaryStage) {


           GridPane root = new GridPane();
           root.setHgap(10);
           root.setVgap(10);

              Scene scene = new Scene(root, 600, 400);

              ComboBox<Person> comboBox1 = new ComboBox<>();
              Label label1 = new Label();

              root.add(new Label("Last item selected: "), 0, 0);
              root.add(comboBox1, 1, 0);
              root.add(label1, 2, 0);

              ComboBox<Person> comboBox2 = new ComboBox<>();
              Label label2 = new Label();

              root.add(new Label("Other item selected: "), 0, 1);
              root.add(comboBox2, 1, 1);
              root.add(label2, 2, 1);

              ObservableList<Person> personList = FXCollections.observableArrayList();
              Person person1 = new Person("name1", 12); //$NON-NLS-1$
              Person person2 = new Person("name2", 33); //$NON-NLS-1$
              Person person3 = new Person("name3", 44); //$NON-NLS-1$
              Person person4 = new Person("name4", 44); //$NON-NLS-1$
              Person person5 = new Person("name5", 44); //$NON-NLS-1$
              Person person6 = new Person("name6", 44); //$NON-NLS-1$

              personList.setAll(person1, person2, person3, person4, person5, person6);


              comboBox1.getSelectionModel().selectedItemProperty().addListener((ob, ov, nv) -> label1.setText(nv.getName()));
              comboBox2.getSelectionModel().selectedItemProperty().addListener((ob, ov, nv) -> label2.setText(nv.getName()));

              comboBox1.setValue(person6);
              comboBox1.itemsProperty().set(personList);

              comboBox2.setValue(person1);
              comboBox2.itemsProperty().set(personList);


              primaryStage.setScene(scene);
              primaryStage.show();


          }

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

          public static class Person {
              private StringProperty nameProperty = new SimpleStringProperty();
              private IntegerProperty ageProperty = new SimpleIntegerProperty();

              public Person(String name, Integer age) {
                  setName(name);
                  setAge(age);
              }

              public StringProperty nameProperty() {
                  return nameProperty;
              }

              public void setName(String name) {
                  nameProperty.set(name);
              }

              public String getName() {
                  return nameProperty.get();
              }

              public IntegerProperty ageProperty() {
                  return ageProperty;
              }

              public void setAge(Integer age) {
                  ageProperty.set(age);
              }

              public Integer getAge() {
                  return ageProperty.get();
              }

              @Override
              public String toString() {
                  return "" + getName() + "/" + getAge(); //$NON-NLS-1$ //$NON-NLS-2$
              }
          }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


            pnarayanaswa Praveen Narayanaswamy
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: