javafx - make ListView not selectable via mouse

前端 未结 7 2187
执念已碎
执念已碎 2020-12-20 16:33

Is there an option in JavaFX to deactivate the possibility to select the items in a ListView via mouse?

I\'d like to just display a ListView

7条回答
  •  半阙折子戏
    2020-12-20 16:57

    @Override
    protected void updateItem(T item, boolean empty) {
        super.updateItem(item, empty);
        updateSelected(false);
    }
    

    Every time you click on a cell, the cell's updateItem will call, so you can deselect it at here. If you check the base class Cell.java. It use this method to prevent empty cell being selected.

    protected void updateItem(T item, boolean empty) {
        setItem(item);
        setEmpty(empty);
        if (empty && isSelected()) {
            updateSelected(false);
        }
    }
    

提交回复
热议问题