JDK-6314014 : ActionListeners on JRadioButtons don't get notified when selection is changed with arrow keys
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2005-08-22
  • Updated: 2011-01-19
  • Resolved: 2005-08-31
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b50Fixed
Related Reports
Relates :  
Relates :  
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();
    }
}

Comments
EVALUATION fix for 4226243 was rolled back so this bug is not relevant now
11-10-2005

EVALUATION This is a regression of the fix for 4226243
22-08-2005