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

ComboBox popup doesn't close after selecting value that was added with 'runLater'

XMLWordPrintable

    • b09
    • b10
    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      The combobox popup won't hide if there is only one selectable value and if if this one value was added with "Platform.runLater". In that specific case the showing and focused-Property of the combobox turn false immediately after showing. So they are false even though the popup is still showing. I guess thats why clicking on that one item does not hide the popup.
      The bug only occur if the value is added with "Platform.runLater" and if there is only value added.
      The source code shows 5 different cases of adding items. The described behavior occurs in case 3 and 5. The other cases work fine.

      I've tested it in other javafx versions but it only occurs with version 19.

      REGRESSION : Last worked in version 18

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. click on the combobox
      2. select the first (and only) value


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      1.
      focused-Property: true
      showing-Property: true
      2.
      focused-Property: true
      showing-Property: false
      -> Popup closes.
      ACTUAL -
      1.
      focused-Property: false
      showing-Property: false
      2.
      focused-Property: false
      showing-Property: false
      -> Popup still showing.

      ---------- BEGIN SOURCE ----------
      package com.arm.comboboxbugdemo;

      import javafx.application.Application;
      import javafx.application.Platform;
      import javafx.scene.Scene;
      import javafx.scene.control.ComboBox;
      import javafx.scene.layout.HBox;
      import javafx.stage.Stage;

      public class ComboBoxBugApplication extends Application {

          ComboBox<String> comboBox;

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

          @Override
          public void start(Stage stage) {

              comboBox = new ComboBox<>();
              comboBox.showingProperty().addListener((observable1, oldValue1, newValue1) -> System.out.println("showing: " + newValue1));
              comboBox.focusedProperty().addListener((observable1, oldValue1, newValue1) -> System.out.println("focused: " + newValue1));

              //try different cases
      // case1(); //no bug
      // case2(); //no bug
              case3(); //bug
      // case4(); //no bug
      // case5(); //bug

              Scene scene = new Scene(new HBox(comboBox), 320, 240);
              stage.setScene(scene);
              stage.show();
          }

          /**
           * no bug
           */
          private void case1() {
              comboBox.getItems().addAll("case1");
          }

          /**
           * no bug
           */
          private void case2() {
              Platform.runLater(() -> comboBox.getItems().addAll("case2", "case2_"));
          }

          /**
           * bug
           */
          private void case3() {
              Platform.runLater(() -> comboBox.getItems().add("case3"));
          }

          /**
           * no bug
           */
          private void case4() {
              comboBox.getItems().addAll("case4", "case4_");
              Platform.runLater(() -> comboBox.getItems().remove("case4"));
          }

          /**
           * bug
           */
          private void case5() {
              comboBox.getItems().addAll("case5", "case5_");
              Platform.runLater(() -> {
                  comboBox.getItems().clear();
                  comboBox.getItems().add("case5");
              });
          }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


            mstrauss Michael Strauß
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: