问题
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.
回答1:
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());
回答2:
Assuming your objects in your JList are clickable items, just do setEnabled(false)
on all the objects you want to disable
来源:https://stackoverflow.com/questions/17863780/make-jlist-values-unselectable