Reputation: 169
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.
Upvotes: 7
Views: 3405
Reputation: 472
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.
Upvotes: 4
Reputation: 46
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;
}
Upvotes: 3
Reputation: 911
Here's at least a workaround: after changing the number of items, also change visibleRowCount to something else and back to your desired value. This seems to trigger an update of the dropdown height, although it was not always accurate in my tests.
Also, if you change visibleRowCount to 10, effectively nothing happens because this is the initial value and setting it to 10 does not invalidate the property.
Upvotes: 0