Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX combobox not refreshing the number of visible rows

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.

like image 404
Scarminio Avatar asked Apr 15 '14 20:04

Scarminio


2 Answers

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.

like image 128
Khrystyna Makar Avatar answered Nov 13 '22 16:11

Khrystyna Makar


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;

}
like image 3
hicyo Avatar answered Nov 13 '22 16:11

hicyo