JDK-6693685 : Auto focus transfer to disabled component
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1,1.4.1
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: generic,windows_2000
  • CPU: generic,x86
  • Submitted: 2008-04-24
  • Updated: 2011-04-28
Related Reports
Duplicate :  
Description
Run the test case below. Click on button two. This disables button two and three. However, the auto focus transfer from the disabling of button two causes focus to go to the also disabled button three, and it can't be moved with tab traversal.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class ButTest extends JFrame {

    private JButton one = new JButton("one");
    private JButton two = new JButton("two");
    private JButton three = new JButton("three");
    private JButton four = new JButton("four");


    public ButTest() {
        super("ButTest");

        setLayout(new FlowLayout());
        add(one);
        add(two);
        add(three);
        add(four);

        two.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                two.setEnabled(false);
                three.setEnabled(false);
            }
        });
    }

    private static void createAndShowGUI(String[] args) {
        ButTest test = new ButTest();
        test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        test.setSize(400, 400);
        test.setLocationRelativeTo(null);
        test.setVisible(true);
    }

    public static void main(final String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI(args);
            }
        });
    }
}

Comments
EVALUATION In the testcase when "two.setEnabled(false)" is called focus is requested to "three" button, not yet disabled. Then "three" button is disabled but it hasn't yet received FOCUS_GAINED and so no autotransfer happens. When it later (asynchronously) receives FOCUS_GAINED we _accept_ it. Actually the Focus Spec allows a disabled coponent be the focus owner. And this is what bounds us. I don't know who needs this functionality. It's not a problem to fix it. The problem is to change the spec. Is there code that relies on this behavior that we can break? The same issue: 4685768.
25-04-2008