如何在Swing中制作只读JCheckBox? [英] How to make read-only JCheckBox in Swing?

查看:88
本文介绍了如何在Swing中制作只读JCheckBox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望复选框列指示持久过程的步骤。

I want to have column of check-boxes indicate the steps of long lasting procedure.

在这种情况下,用户不应更改复选框。

In this case check-boxes should not be changeable by users. They are changed by background process.

不幸的是,如果我调用 setEnable(false),我不会选中复选框

Unfortunately, if I call setEnable(false) I make check-box not only read-only, but also dimmed.

如何完成?

推荐答案

从复选框中删除MouseListener和键绑定。

Remove the MouseListener and Key Bindings from the check box.

MouseListener[] ml = (MouseListener[])checkBox.getListeners(MouseListener.class);

for (int i = 0; i < ml.length; i++)
    checkBox.removeMouseListener( ml[i] );

InputMap im = checkBox.getInputMap();
im.put(KeyStroke.getKeyStroke("SPACE"), "none");
im.put(KeyStroke.getKeyStroke("released SPACE"), "none");

这篇关于如何在Swing中制作只读JCheckBox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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