Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6463708

DefaultButtonModel.setMnemonic generates ChangeEvent for no change

    XMLWordPrintable

    Details

      Description

      FULL PRODUCT VERSION :
      java version "1.5.0_06"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
      Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)


      ADDITIONAL OS VERSION INFORMATION :
      Linux localhost 2.6.13-gentoo-r5 #4 SMP Mon Oct 31 16:51:12 GMT 2005 i686 Intel(R) Pentium(R) M processor 1.80GHz GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      For a DefaultButtonModel, setMnemonic() generates a ChangeEvent even if the new value is the same as the old value (that is, nothing has changed). This is inconsistent with other methods in the same class, and throughout Swing. Please correct this, or document the behaviour.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run test app below.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Event triggered: true
      Event triggered: false

      ACTUAL -
      Event triggered: true
      Event triggered: true


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.DefaultButtonModel;
      import javax.swing.event.ChangeEvent;
      import javax.swing.event.ChangeListener;

      public class DefaultButtonModelTest implements ChangeListener
      {

        public ChangeEvent lastEvent;
        
        public DefaultButtonModelTest()
        {
        }

        public void stateChanged(ChangeEvent e)
        {
          lastEvent = e;
        }
        
        public static void main(String[] args)
        {
          DefaultButtonModelTest test = new DefaultButtonModelTest();
          DefaultButtonModel m = new DefaultButtonModel();
          m.addChangeListener(test);
          m.setMnemonic(70);
          System.out.println("Event triggered: " + (test.lastEvent != null));
          
          // clear the recorded event, set the same mnemonic then check if another
          // event is triggered...
          test.lastEvent = null;
          m.setMnemonic(70);
          System.out.println("Event triggered: " + (test.lastEvent != null));
        }

      }
      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Imported:
              Indexed: