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

ComboBox dropdown listview has inconsistent height, does not fit items

XMLWordPrintable

    • generic
    • generic

      FULL PRODUCT VERSION :
      java version "1.8.0_144"
      Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
      Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 10.0.15063]

      A DESCRIPTION OF THE PROBLEM :
      combobox dropdown list does not have correct height when provided code is run for the first time after application start, height changes when listview is closed and reopened. When list is cleared and dropdown is opened again, which triggers loading data again, height is correct MOST of the time, but not always!

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      start provided application, click to dropdown combobox

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      combobox listview should show consistent number of items on each dropdown and resize to fit number of items when list contains less items than before.
      ACTUAL -
      listview is always a bit too short directly after loading data for the first time, but has correct size after closing and reopening, and has correct size most of the time on subsequent loadings

      REPRODUCIBILITY :
      This bug can be reproduced always.

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

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

      @Override
      public void start(Stage primaryStage) throws Exception {
      ObservableList <Integer> items = FXCollections.observableArrayList();
      LoaderService service = new LoaderService();

      Label pi = new Label("please wait...");
      ComboBox <Integer> cb = new ComboBox <> (items);
      cb.setPrefWidth(150);
      cb.setPlaceholder(pi);
      cb.setOnShown(ev -> {
      ListView <?> lv = ((ComboBoxListViewSkin <?>) cb.getSkin()).getListView();
      lv.setMinHeight(70);
      lv.autosize();
      System.out.println("onShown " + lv.getHeight());
      if (items.isEmpty()) service.restart();
      });
      service.setOnSucceeded(ev -> {
      items.setAll(service.getValue());
      ListView <?> lv = ((ComboBoxListViewSkin <?>) cb.getSkin()).getListView();
      lv.autosize();
      System.out.println("onSucceeded " + lv.getHeight());
      });

      Button reset = new Button("reset");
      reset.setOnAction(event -> items.clear());

      TilePane root = new TilePane();
      Scene scene = new Scene(root, 500, 300);
      root.getChildren().addAll(cb, reset);
      primaryStage.setScene(scene);
      primaryStage.show();
      }

      class LoaderService extends Service <List <Integer>> {

      Random rd = new Random();

      @Override
      protected Task <List <Integer>> createTask() {
      return new Task <List <Integer>> () {

      @Override
      protected List <Integer> call() throws Exception {
      Thread.sleep(1500);
      return Stream.iterate(1, i -> i+1).limit(rd.nextInt(6) + 5).collect(Collectors.toList());
      }
      };
      }

      }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      none found

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: