使JList值不可选择 [英] Make JList Values Unselectable

查看:80
本文介绍了使JList值不可选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何修改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.

推荐答案

我通过使用以下类解决了该问题:

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

这篇关于使JList值不可选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆