JavaFx Combobox drop down list width is less on first click on Combo box


Question

when I click on the ComboBox the first time and the popup menu list that is shown has its width very short. The second time I click on the ComboBox and the list is shown again, the width is now correct as the width of the list now aligns itself with the Combbox.

enter image description here

i tried to alter the width of the drop down on mouse click on the combo box. But it did not work,

final ComboBox<String> combo = new ComboBox<String>();
combo.getStyleClass().add("combo-border");
combo.setMinWidth(100.0);
combo.setEditable(true);
combo.setOnMouseClicked(new EventHandler<MouseEvent>() {

    @Override
    public void handle(MouseEvent arg0) {
        combo.setMinWidth(100.0); // Did not work
        //csectCombo.setPrefWidth(100.0); // Did not work
    }
});

I am using Javafx 2.2. Is there any workaround for this?

From the below post, it says that is the known bug in JavaFx 2 and has been fixed in JavaFx 8.

http://tech.chitgoks.com/2013/09/20/width-of-combobox-popup-list-is-too-small-in-java-fx-2/

1
3
3/21/2014 5:55:29 AM

Accepted Answer

Try this

final ComboBox<String> combo = new ComboBox<String>();
combo.getStyleClass().add("combo-border");
combo.setMinWidth(100.0);
combo.setEditable(true);
combo.setPrefWidth(combo.getMinWidth());
3
3/24/2014 6:58:05 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon