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

Some Swing classes have inconsistent policy for generating events.

XMLWordPrintable


      jim.marks@Eng 1999-12-03

      JCheckBox and JComboBox behave differently with respect to even generation
      for code-triggered actions (as opposed to user-triggered).

      To reproduce the problem:

      1. Write a program which uses both JCheckBox and JComboBox.

      2. Add an ActionListener for instances of each of the above classes. Put
         a println() at the top of each of the actionPerfomed handlers.

      3. As part of the constructor for the main class, call

      <checkbox>.setSelected(true).

      <combobox>.setSelectedIndex(<some-valid-index>.

      4. You should see that the println() for the combo box is executed, but
         the one for the checkbox is not executed.

      Looks like the JCheckBox case (via setPressed function of JToggleButton)
      causes a ChangeEvent only, whereas setSelectedIndex of JComboBox
      causes both a ChangeEvent and ActionEvent to be triggered. From the
      application writer's perspective, it would be helpful if these the behavior
      was normalized across all Swing components.

            peterz Peter Zhelezniakov
            jmarks Jim Marks (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: