Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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/

like image 286
AJJ Avatar asked Sep 07 '25 01:09

AJJ


1 Answers

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());
like image 139
Uluk Biy Avatar answered Sep 08 '25 16:09

Uluk Biy