JOptionPane 出现在选定的 JCheckBox 上 [英] JOptionPane to appear on selected JCheckBox

查看:54
本文介绍了JOptionPane 出现在选定的 JCheckBox 上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我在 JcheckBox 侦听器中添加 joptionpane 时遇到了一些困难

<预><代码>公共无效 itemStateChanged(ItemEvent evt) {if(evt.getStateChange() == ItemEvent.SELECTED){///一些代码JOptionPane.showMessageDialog(null, "Message", "Alert",JOptionPane.INFORMATION_MESSAGE);}}

所以它工作正常,但问题是 JCheckBox 被选中并立即取消选中我该如何解决这个问题?

干杯

解决方案

这里有一些建议(解决方案)使用动作侦听器而不是项目侦听器.但是,这确实有效,但我觉得很奇怪,因为我建议的所有文本都建议项目侦听器是复选框的预期侦听器类型.

事实上,这是 Oracle 错误 ID:6924233 JOptionPane 显然会导致生成另一个事件.

推荐的修复方法是使用 invokeLater 调用 JOptionPane.这工作正常,并且只涉及对已将项目侦听器用于其他目的的程序进行微小的代码更改.

Hi all I am having some difficulties with adding a joptionpane in JcheckBox listener


public void itemStateChanged(ItemEvent evt) {

            if(evt.getStateChange() == ItemEvent.SELECTED){
                    ///some code

                        JOptionPane.showMessageDialog(null,  "Message", "Alert",
                                JOptionPane.INFORMATION_MESSAGE);
            }
    }

so it works fine,but the problem is that the JCheckBox gets selected and immediately deselected how can I manage to fix this ?

Cheers

解决方案

There are a couple of suggestions here (solution) to use an action listener instead of a item listener. This does work, however, I though it strange given that all the texts I have suggest an item listener is the expected type of listener for a check box.

In fact, this is a known bug as acknowledged by Oracle Bug ID:6924233 The JOptionPane apparently causes another event to be generated.

The recommended fix is to invoke the JOptionPane using invokeLater. This works fine and involves only a minor code change to a program already using an item listener for other purposes.

这篇关于JOptionPane 出现在选定的 JCheckBox 上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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