Make JList Values Unselectable

nrubin29 picture nrubin29 · Jul 25, 2013 · Viewed 10.4k times · Source

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.

Answer

nrubin29 picture nrubin29 · Jul 25, 2013

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());