I'm changing the items on a combo-box dynamically. It's working perfectly, except that the number of visible rows remains fixed according to the first time the combo-box is clicked.
Example: The combobox items are set to A and B. When I click the combobox, it shows 2 rows with A and B. Then I change dynamically the items to C, D and E. When I click the combobox, it shows 2 rows with C and D and a scrollbar.
I already set the
comboBox.setVisibleRowCount(10);
but it keeps showing only 2 rows and a scrollbar.
If I do the opposite, first set the items to C, D and E and click the combobox; it shows the three visible rows. Then I change dynamically the items to A and B. When I click the combobox, it shows 3 rows! A, B and a blank row.
Try this:
box.hide(); //before you set new visibleRowCount value
box.setVisibleRowCount(rows); // set new visibleRowCount value
box.show(); //after you set new visibleRowCount value
It's works for me.
There is an issue already submitted in Javafx issue traker. https://javafx-jira.kenai.com/browse/RT-37622
It only works if the combobox has a fixed cell size. I did that with css.
for example:
.combo-box .list-view .list-cell{
-fx-cell-size: 35;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With