Why does setSelected on JCheckBox lose effect?

后端 未结 2 455
伪装坚强ぢ
伪装坚强ぢ 2020-11-27 23:16

Can someone explain to me why I lost the selection (set by setSelected()) for JCheckBox when I put the JOptionPane into the Item

2条回答
  •  眼角桃花
    2020-11-28 00:13

    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) 
    

提交回复
热议问题