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.
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();
}
}