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

[ComboBox] ComboBox popup does not adjust its size properly when the items are changed

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 8u60
    • 8u20
    • javafx
    • Java 8u-dev repo tip. Windows 7

      I have a ComboBox whose items are controlled by other choices in the UI. I have noticed that in Windows that when the items change have changed and you click on the ComboBox to view the popup it is often not at the correct size for the new items.

      Run the provided test class in Windows:

      1. Click on the ComboBox to view its popup.

      2. Click on the "Change combo contents" button.

      3. Click on the ComboBox again to view its popup. It appears at the same size as the first time but with a scrollbar showing. It should have resized bigger in both dimensions.

      4. Select the "three three" item and notice that now the ComboBox resizes but if you click on it again the popup is still too small.

      I have run the same test in Linux and the popup always seems to be the correct size. I haven't had a chance to try the same test in OS X.


      ****************************************** Test Class ************************************************
      import java.util.ArrayList;
      import java.util.List;

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.ComboBox;
      import javafx.scene.layout.Region;
      import javafx.scene.layout.StackPane;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class ComboBoxTest extends Application {

         @Override
         public void start(final Stage primaryStage) throws Exception {
            
            primaryStage.centerOnScreen();
            primaryStage.setHeight(200);
            primaryStage.setWidth(300);

            List<String> list1 = new ArrayList<>();
            list1.add("one");
            list1.add("two");
            list1.add("three");
            
            List<String> list2 = new ArrayList<>();
            list2.add("one");
            list2.add("two");
            list2.add("three three");
            list2.add("four");
            
            final ComboBox<String> combo = new ComboBox<String>();
            combo.getItems().setAll(list1);
            
            Button button = new Button("Change combo contents");
            button.setOnAction(event -> {
               if ( combo.getItems().size() == 3 ) {
                  combo.getItems().setAll(list2);
               } else {
                  combo.getItems().setAll(list1);
               }
            });
            
            VBox box = new VBox(20, combo, button );
            box.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
            primaryStage.setScene(new Scene( new StackPane(box) ));

            primaryStage.show();

         }

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

      }

        1. screen1.png
          31 kB
          Steve Northover
        2. screen2.png
          22 kB
          Steve Northover

            jgiles Jonathan Giles
            csmithjfx Charles Smith (Inactive)
            Votes:
            2 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: