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

[ComboBox, Windows] popup doesn't shrink when items are removed

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Cannot Reproduce
    • Affects Version/s: 8u25
    • Fix Version/s: 8u40
    • Component/s: javafx
    • Labels:
    • Environment:

      Reproduced on: 8u25 on Windows 7, Windows 8.1
      Works as expected on 8u5 & 8u25 on OS X Mavericks and Ubuntu

      Description

      Creating a ComboBox with an ObservableList as the source does show the contained items in the popup as expected. Opening the popup again after removing an item from the ObservableList shows white spaces at the end of the popup list. The popup doesn't seem to 'shrink' as expected. Possibly related: RT-37622 RT-39030 RT-38731

      - Removing an item *before* opening the popup for the first time works as expected.
      - setVisibleRowCount() doesn't work after the popup has been opened before.
      - Reproduced on (probably not limited to) 8u25 on Windows 7 & Windows 8.1 x64
      - Works on OS X Mavericks 8u5, 8u25 & Ubuntu (unknown version) 8u25 as expected.

      The following example shows the unexpected behavior (apparently only on Windows systems):


      package comboboxquirk;

      import javafx.application.Application;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.ComboBox;
      import javafx.scene.control.Label;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      /**
       * - ComboBox will be filled with an ObservableList containing 7 Strings
       * - Opening the ComboBox shows the 7 Strings as expected
       * - Clicking the Button once removes the 4. String-item ("Cucumber") from the ObservableList
       * - Expected: The String-item "Cucumber" is removed from the pupup-list, the list only shows the remaining items
       * - Actual: The String-item "Cucumber" HAS been removed, BUT the popup-list shows an additional blank item at the end
       *
       * @author Arjan
       */
      public class ComboBoxQuirk extends Application {

          ObservableList<String> demoList;

          @Override
          public void start(Stage primaryStage) {

              // Simple VBox, displaying a ComboBox and a Button
              VBox vbox = new VBox();

              // Setting up the demo list
              demoList = FXCollections.observableArrayList();
              demoList.add("Apple");
              demoList.add("Banana");
              demoList.add("Pineapple");
              demoList.add("Cucumber");
              demoList.add("Coconut");
              demoList.add("Pumpkin");
              demoList.add("Zucchini");

              // ComboBox
              ComboBox<String> comboBox = new ComboBox<>(demoList);
              comboBox.prefWidthProperty().bind(vbox.widthProperty());
              comboBox.maxWidth(Double.MAX_VALUE);

              // Button, removes String "Cucumber" when pressed once (further items, subsequently)
              Button button = new Button("Remove Item");
              button.prefWidthProperty().bind(vbox.widthProperty());
              button.maxWidth(Double.MAX_VALUE);
              button.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent event) {
                      demoList.remove(3);
                  }
              });

              Label label = new Label("Notice the content of the ComboBox. Pressing the Button will remove an Item. Now the ComboBox shows strange white blanks.\nWhen removing an item *before* looking at the ComboBox's content, everything's fine.");
              label.setWrapText(true);

              // Add ComboBox and Button to VBox
              vbox.getChildren().addAll(comboBox, button, label);
              vbox.setSpacing(5);

              // Setup scene and display the window
              Scene scene = new Scene(vbox, 350, 150);
              primaryStage.setTitle("ComboBox Quirk");
              primaryStage.setResizable(false);
              primaryStage.setScene(scene);
              primaryStage.show();
          }

          /**
           * @param args the command line arguments
           */
          public static void main(String[] args) {
              launch(args);
          }

      }

        Attachments

          Activity

            People

            • Assignee:
              jgiles Jonathan Giles
              Reporter:
              duke J. Duke (Inactive)
            • Votes:
              1 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: