Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select Multiple Items In JList Without Using The Ctrl/Command Key

I am looking for a way to select multiple items within a JList by just clicking each item.

The normal way to do this is to hold the command/ctrl key and then click.

I think it would be more intuitive just to allow the user to click the items on and off without the need to hold an additional key.

like image 648
Gordon Avatar asked Mar 08 '10 20:03

Gordon


1 Answers

Think twice before changing default behavior. Unless you have some special use-case, I'd not like my List to work different than everywhere else :)

Having said that, you should be able to use your own ListSelectionModel:

list.setSelectionModel(new DefaultListSelectionModel() {
    @Override
    public void setSelectionInterval(int index0, int index1) {
        if(super.isSelectedIndex(index0)) {
            super.removeSelectionInterval(index0, index1);
        }
        else {
            super.addSelectionInterval(index0, index1);
        }
    }
});
like image 172
Peter Lang Avatar answered Oct 13 '22 10:10

Peter Lang