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

ActionListeners on JRadioButtons don't get notified when selection is changed with arrow keys

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b50
    • CPU:
      generic
    • OS:
      generic

      Description

      When you have several radiobuttons which belong to one buttongroup you can move the selection with help of arrow keys, but when selection is changed only ItemListener get notified.

      Expected behaviour:
      ActionListener should be notified as well

      This test shows the problem:

      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.ActionListener;
      import java.awt.event.ActionEvent;
      import java.awt.event.ItemListener;
      import java.awt.event.ItemEvent;

      public class TheBug {
          public static void main(String args[]) {
              JFrame frame = new JFrame();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              
              frame.setLayout(new FlowLayout());
              JRadioButton one = new JRadioButton("One");
              final JRadioButton two = new JRadioButton("Two");
              
              two.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      System.out.println("PossibleBug.actionPerformed");
                  }
              });
              
              ButtonGroup group = new ButtonGroup();
              
              group.add(one);
              group.add(two);
              
              frame.add(one);
              frame.add(two);
              
              one.addItemListener(new ItemListener() {
                  public void itemStateChanged(ItemEvent e) {
                      System.out.println("PossibleBug.itemStateChanged");
                  }
              });
              one.setSelected(true);

              frame.setSize(new Dimension(300, 200));
              frame.setVisible(true);
              one.requestFocusInWindow();
          }
      }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              alexp Alexander Potochkin (Inactive)
              Reporter:
              alexp Alexander Potochkin (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: