JavaFX Layout Does Not Update Number of Visible Lines

I am changing elements in a combo box dynamically. It works fine, except that the number of visible lines remains fixed according to the first mouse click.

Example. The combobox elements are set to A and B. When I click on the drop-down list, it shows 2 lines with A and B. Then I dynamically change objects to C, D and E. When I click on the combo box, it shows 2 lines with C and D and scroll bar.

I have already installed

comboBox.setVisibleRowCount(10); 

but it shows only 2 lines and a scrollbar.

If I do the opposite, first set the elements to C, D and E and click on the combo box; it shows three visible lines. Then I dynamically change objects to A and B. When I click on the combo box, it shows 3 lines! A, B and empty string.

+7
javafx combobox
source share
3 answers

There is a problem already submitted to Jawafx issue traker. https://javafx-jira.kenai.com/browse/RT-37622

It only works if there is a fixed cell size in the combo box. I did this with css.

eg:

 .combo-box .list-view .list-cell{ -fx-cell-size: 35; } 
+3
source share

Try the following:

 box.hide(); //before you set new visibleRowCount value box.setVisibleRowCount(rows); // set new visibleRowCount value box.show(); //after you set new visibleRowCount value 

This works for me.

+2
source share

Here is at least a workaround: after changing the number of elements, also change visibleRowCount to something else and back to the desired value. This seems to have caused the dropdown menu height to be updated, although in my tests this was not always accurate.

In addition, if you change visibleRowCount to 10, virtually nothing happens, because this is the initial value and setting it to 10 does not invalidate the property.

0
source share

All Articles