9

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.

4

2 回答 2

14

我通过使用以下类解决了它:

class DisabledItemSelectionModel extends DefaultListSelectionModel {

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

我在这里实例化了这个类:

console.setSelectionModel(new DisabledItemSelectionModel());

于 2013-07-25T16:49:35.777 回答
3

假设您的 JList 中的对象是可点击的项目,只需setEnabled(false)对您要禁用的所有对象执行

于 2013-07-25T16:41:26.240 回答