Make JList Values Unselectable

java, jlist, swing

Solution

I solved it by using the following class:

class DisabledItemSelectionModel extends DefaultListSelectionModel {

    @Override
    public void setSelectionInterval(int index0, int index1) {
        super.setSelectionInterval(-1, -1);
    }
}

I instantiated the class here:

`console.setSelectionModel(new DisabledItemSelectionModel());`

Problem

I was wondering how to modify a `JList` so that clicking any values would not do anything. I have looked at other questions but none have helped.

Original source

Related problems