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

[ComboBox] Popup does not respond to visibleRowCountProperty after it was shown for the first time

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 8u40
    • 8u5, 8u20
    • javafx
    • None
    • Windows 7 SP 1 64bit
      Java 8u5 (32bit) released version
      Java 8u20 b23 (32bit)

    Description

      The visibleRowCountProperty of a ComboBox only seems to have an affect on the popup of the combo box if the value is set before the popup is opened for the first time. Any changes applied afterwards do not have any effect on the reopened popup of a combo box.

      Below is a piece of code which shows this behavior.

      Explanation for the example:
      If you open the combo box without clicking on the button, a popup with two elements is shown. As soon as you click on the button, the items of the combo box are replaced by a list containing four elements and the visible row count is set to 4 which is reflected by the right label. However, when you open the popup of the combo box, the height is still the one for two rows.
      You could also press the button first, open the combo box, press the button again and open the combo box again to simulate the behavior when the visible row count is larger at the beginning and reduced after the popup was shown. In this case, the popup is always high enough for four items.


      import java.util.Arrays;

      import javafx.application.Application;
      import javafx.beans.property.SimpleStringProperty;
      import javafx.collections.FXCollections;
      import javafx.collections.ObservableList;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.ComboBox;
      import javafx.scene.control.Label;
      import javafx.scene.layout.HBox;
      import javafx.stage.Stage;

      public class ComboBoxVisibleRowCountSample extends Application {

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

          @Override
          public void start(Stage primaryStage) {
              ObservableList<Integer> fourItemsObservableList = FXCollections.observableList(Arrays.asList(2, 3, 4, 5));
              ObservableList<Integer> twoItemsObservableList = FXCollections.observableList(Arrays.asList(7, 8));

              ComboBox<Integer> comboBox = new ComboBox<>(twoItemsObservableList);
              comboBox.setVisibleRowCount(comboBox.getItems().size());

              Button button = new Button("Change items of combo box");
              button.setOnAction(event -> {
                  ObservableList<Integer> observableList;
                  if (comboBox.getItems().equals(fourItemsObservableList)) {
                      observableList = twoItemsObservableList;
                  } else {
                      observableList = fourItemsObservableList;
                  }
                  comboBox.setItems(observableList);
                  comboBox.setVisibleRowCount(observableList.size());
              });

              Label visibleRowCountLabel = new Label();
              visibleRowCountLabel.textProperty().bind(new SimpleStringProperty("visible row count: ").concat(comboBox.visibleRowCountProperty().asString()));

              HBox root = new HBox(20, comboBox, button, visibleRowCountLabel);


              Scene scene = new Scene(root, 400, 150);
              primaryStage.setScene(scene);
              primaryStage.show();
          }
      }

      Attachments

        Issue Links

          Activity

            People

              msladecek Martin Sládeček
              duke J. Duke
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported: