7

I'm trying to avoid horizontal scrolling in ListView. The ListView instance holds list of HBox items, each item has a different width.

So far I'm using such a cell factory:

public class ListViewCell extends ListCell<Data>
{
    @Override
    public void updateItem(Data data, boolean empty)
    {
        super.updateItem(data, empty);
        if(empty || data == null){
            setGraphic(null);
            setText(null);
        }
        if(data != null)
        {
            Region region = createRow(data);
            region.prefWidthProperty().bind(mListView.widthProperty().subtract(20));
            region.maxWidthProperty().bind(mListView.widthProperty().subtract(20));
            setGraphic(region);
        }
    }
}

Unfortunately it is not enough. Usually after adding several items ListView's horizontal scrollbar appears. Even if it seems to be unnecessary.

How can I assure, that ListViewCell will not exceed it's parent width and horizontal scrollbar will not appear?

Dejwi
  • 4,225
  • 11
  • 43
  • 67
  • 5
    I do not want to hide the horizontal scrollbar. I want to eliminate possibility, that it will be needed. – Dejwi Oct 01 '16 at 21:23
  • 1
    i simply use row.prefWidthProperty().bind(listviwe.widthProperty().divide(1.1)); row.setMaxWidth(Control.USE_PREF_SIZE); – Door D Uthpala Nov 24 '20 at 19:21

0 Answers0