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

ComboBox: adding an item from editor changes editor text

XMLWordPrintable

    • b04
    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      JavaFX 23-ea+3. Java; openjdk version "22.0.1" 2024-04-16; Ubuntu 20.04.3 LTS


      A DESCRIPTION OF THE PROBLEM :
      When a value from editable comboBox is added to comboBox items then editor value changes.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the provided code. After that enter in ComboBox field "test" and click the button.
      More info:
      https://stackoverflow.com/questions/78511921/adding-to-combobox-items-list-a-text-from-editor-changes-editor-text-in-javafx

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      After clicking the button editor value musn't change.
      ACTUAL -
      After clicking the button editor value changes.

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

          @Override
          public void start(Stage stage) {
              var list = List.of("A", "B", "C");
              var comboBox = new ComboBox<String>();
              comboBox.setEditable(true);
              comboBox.setItems(FXCollections.observableArrayList(list));

              var button = new Button("Push Me");
              button.setOnAction(e -> {
                  comboBox.getItems().add(0, comboBox.getValue());
              });

              Scene scene = new Scene(new VBox(comboBox, button), 400, 200);
              stage.setScene(scene);
              stage.show();
          }

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

      FREQUENCY : always


        1. n3GWGlPN.gif
          n3GWGlPN.gif
          22 kB
        2. Test.java
          0.9 kB

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

              Created:
              Updated:
              Resolved: