Make JList Values Unselectable [duplicate]

▼魔方 西西 提交于 2019-12-21 09:36:45

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!