JDK-4801705 : Focus stuck on disabled JButton when MenuItem calls setenabled(false)
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.1
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-01-10
  • Updated: 2009-06-15
  • Resolved: 2009-06-15
Related Reports
Duplicate :  
Relates :  
Description
Name: jk109818			Date: 01/10/2003


FULL PRODUCT VERSION :
java version "1.4.0_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_02-b02)
Java HotSpot(TM) Client VM (build 1.4.0_02-b02, mixed mode)

FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195] SP3

A DESCRIPTION OF THE PROBLEM :
If a button has focus and a menu selection disables the
action associated with it then the button does not transfer
focus to another button.

This might be related to bug 4685768

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the example program given.
2. Choose the menu option to Disable
3. Focus locks on Message button but it is greyed out

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
// FocusTest.java

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

public class FocusTest extends JFrame {

  public static void main(String [] args) {
    new FocusTest().show();
  }

  Action action1,action2;

  public FocusTest() {
    getContentPane().setLayout(new FlowLayout());

    action1 = new MessageAction();
    action2 = new DisableAction();

    setDefaultCloseOperation(EXIT_ON_CLOSE);

    getContentPane().add(new JButton(action1));
    getContentPane().add(new JButton(action2));

    JMenu menu = new JMenu("File");
    menu.setMnemonic('F');

    menu.add(new JMenuItem(action1));
    menu.add(new JMenuItem(action2));

    setJMenuBar(new JMenuBar());
    getJMenuBar().add(menu);

    pack();
  }

  class DisableAction extends AbstractAction {
    DisableAction() {
       super("Disable");
       putValue(ACCELERATOR_KEY,KeyStroke.getKeyStroke("alt D"));
    }

    public void actionPerformed(ActionEvent evt) {
        action1.setEnabled(false);
    }
  }

  class MessageAction extends AbstractAction {
    MessageAction() {
       super("Message");
    }

    public void actionPerformed(ActionEvent evt) {
        JOptionPane.showMessageDialog(null,"Hello");
    }
  }
}

  

---------- END SOURCE ----------

CUSTOMER WORKAROUND :
Move the focus programatically before disabling the action
(Review ID: 179389) 
======================================================================

Comments
EVALUATION Name: osR10079 Date: 01/15/2003 As far as i know, after menu closing swing returns focus to component which was a focus owner before menu showing. So if we'll decide that this is a bug then Swing will need to fix it. But, from the other hand, it's not clear if this is a bug. According to new Focus API, disabled component could be a focus owner, although this produce some accessibility problems (see bugid 4685768 (A11y issue - Focus set to disabled component, can't Tab/Shift-Tab)). So, i think we should make decision on focusability of disabled component before reassigning this bug to Swing. ###@###.### 2003-01-15 ======================================================================
15-01-2003