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

ChoiceBox: adding ~1000 items takes a long time

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • jfx20
    • javafx
    • None
    • generic
    • generic

      When large number of items(~1000) are added to the ChoiceBox, it takes more than 2-3 seconds and loading beach ball is shown in Mac. In windows the application becomes not responding while the items are added.

      This can be reproduced with following code or using monkey tester available in the link given below.
      Monkey tester: https://github.com/andy-goryachev-oracle/Test/blob/main/src/goryachev/monkey/MonkeyTesterApp.java

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.ChoiceBox;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class ChoiceBoxSample extends Application {
          @Override
          public void start(Stage stage) throws Exception {
              ChoiceBox<String> choiceBox = new ChoiceBox<String>();

              Button button = new Button("Add 1000 items");
              button.setOnAction(event -> {
                  ObservableList<String> itemsTwoHundred = FXCollections.observableArrayList();
                  for(int i=0 ; i<1000 ; i++) {
                      itemsTwoHundred.add("item " + (i + 1));
                  }
                  choiceBox.getItems().setAll(itemsTwoHundred);
              });

              Scene scene = new Scene(new VBox(choiceBox, button), 250, 200);
              stage.setScene(scene);
              stage.show();
          }
          public static void main(String[] args) {
              launch(args);
          }
      }
      ---------- END SOURCE ----------

      Steps to reproduce:
      1. Run the above code
      2. Click Add 1000 items button

      The items takes time to get added to choicebox and loading cursor is shown.
       

            Unassigned Unassigned
            kpk Karthik P K
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: