Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Combobox, visible count row not applied and doesn't change

user1083804Oct 15 2014 — edited Oct 16 2014

I have noticed a strange behavior of Combobox element. The number of visible rows is not the same established by setVisibleRowCount() method. It happens when changing the items list dynamically.

The following example reproduces it. I think it is Javafx 8 bug.

I have tried unsuccessfully to trigger some event indirectly to refresh the combobox drop down.

import javafx.application.Application;

import javafx.scene.Scene;

import javafx.scene.control.Button;

import javafx.scene.control.ComboBox;

import javafx.scene.layout.HBox;

import javafx.stage.Stage;

public class TestComboBox extends Application {

    private int count;

    public static void main(String[] args) {

        launch(args);

    }

    @Override

    public void start(Stage primaryStage) throws Exception {

        ComboBox<String> combo = new ComboBox<String>();

        combo.setVisibleRowCount(7);

        Button changeButton = new Button();

        changeButton.setText("change items");

        changeButton.setOnAction(evt -> {

            combo.getItems().clear();

            int rows = 10;

            if (count % 2 == 0) {

                rows = 2;

            }

            count++;

            System.out.println("rows: " + rows);

            for (int i = 0; i < rows; i++) {

                combo.getItems().add("item " + i);

            }

        });

        HBox root = new HBox();

        root.getChildren().add(combo);

        root.getChildren().add(changeButton);

        Scene scene = new Scene(root);

        primaryStage.setScene(scene);

        primaryStage.show();

    }

}

Thanks

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 13 2014
Added on Oct 15 2014
1 comment
1,244 views