Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make JList Values Unselectable [duplicate]

Tags:

java

swing

jlist

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.

like image 956
nrubin29 Avatar asked Jul 25 '13 16:07

nrubin29


1 Answers

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

like image 90
nrubin29 Avatar answered Sep 18 '22 16:09

nrubin29