Why does setSelected on JCheckBox lose effect?

偶尔善良 提交于 2019-11-26 21:03:49
SteveJP

It is a known bug as acknowledged by Oracle Bug ID:6924233 The JOptionPane apparently causes another event to be generated with a check box value = false.

The recommended fix is to instantiate the JOptionPane using invokeLater.

Submitted On 09-MAR-2010

The change is in the BasicButtonListener -  Method focusLost()

In 1.6.0_18 it is

       ...
       ButtonModel model = b.getModel();
       model.setPressed(false);
       model.setArmed(false);

in 1.6.0_10 it was

       ...
       ButtonModel model = b.getModel();
       model.setArmed(false);
       model.setPressed(false);

(The order of the statements changed)

And a setPressed(false) with armed==true leads on an ToggleButton like 
the JCheckBox to a change of the selection (see ToggleButtonModel) 

On Mac OS X & Ubuntu I don't see any difference: Starting from the DESELECTED state, I click on the checkbox. I see the check mark appear immediately, followed by the option pane. I get the same result with or without the Runnable.

On Windows, the result is as described, but I see a tiny flicker of the check mark as the option pane comes to the foreground. The effect is easier to see in an emulator, such as VirtualBox, which can slow things down. Queueing the Runnable restores normal operation.

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