JDK-4513801 : requestFocus on an editable JComboBox sends focus to the combobox button
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2001-10-11
  • Updated: 2001-10-11
  • Resolved: 2001-10-11
Related Reports
Duplicate :  
Description

Name: yyT116575			Date: 10/11/2001


java version "1.4.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta2-b77)
Java HotSpot(TM) Client VM (build 1.4.0-beta2-b77, mixed mode)



Calling requestFocus() on an editable JComboBox sends the focus to the combobox
button instead of sending focus to the editor component.

Test: Run the attached program.
Result: The combobox button has the focus.


import java.awt.FlowLayout;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;


public class TestBug6 extends JFrame {

  JComboBox comboBox;

  public TestBug6(String name) {
    super(name);

    JPanel panel = new JPanel(new FlowLayout());

    JTextField textField = new JTextField(10);
    panel.add(textField);

    comboBox = new JComboBox(new String[]{"One", "Two", "Three"});
    comboBox.setEditable(true);
    panel.add(comboBox);

    getContentPane().add(panel);

  }

  public void setComboBoxFocus() {
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        comboBox.requestFocus();
      }
    });
  }

  public static void main(String[] args) {
    TestBug6 test = new TestBug6("TestBug");
    test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    test.pack();
    test.setLocation(100, 70);
    test.setVisible(true);

    test.setComboBoxFocus();
  }
}
(Review ID: 133582) 
======================================================================

Comments
WORK AROUND Name: yyT116575 Date: 10/11/2001 Request focus to the combobox editor component: comboBox.getEditor().getEditorComponent().requestFocus(); ======================================================================
11-06-2004