JDK-4513773 : requestFocus on an editable JComboBox sends focus to the combobox button
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.3.0,1.4.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,windows_nt,windows_2000
  • CPU: generic,x86
  • Submitted: 2001-10-11
  • Updated: 2003-04-12
  • Resolved: 2002-08-12
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.
1.4.2 mantisFixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  

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) {

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

    JTextField textField = new JTextField(10);

    comboBox = new JComboBox(new String[]{"One", "Two", "Three"});



  public void setComboBoxFocus() {
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {

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

    test.setLocation(100, 70);

(Review ID: 133582) 

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mantis mantis-b02 FIXED IN: mantis mantis-b02 INTEGRATED IN: mantis mantis-b02

PUBLIC COMMENTS The situation in which the editable combo box as a table cell editor is mostly fixed. Pressing F2 will put the focus on the editable portion of the combo box. However, this exposes another bug in which an enter pressed on the value to accept the edited contents will move the focus outside the table rather than to the edited cell. This is because of an incorrect focus cycle when composite components are used as a table cell editor. This bug existed before this fix and will be filed under a separate bug. ###@###.### 2002-06-21

WORK AROUND Name: yyT116575 Date: 10/11/2001 Request focus to the combobox editor component: comboBox.getEditor().getEditorComponent().requestFocus(); ====================================================================== Create a static adapter (stateless so it can be reused): // XXX workaround for 4513773 public static class FocusHandler extends FocusAdapter { public void focusGained(FocusEvent evt) { JComboBox cb = (JComboBox)evt.getSource(); if (cb.isEditable()) { Component editor = cb.getEditor().getEditorComponent(); if (editor != null) { editor.requestFocus(); } } } } Add the FocusListener to your editable combo boxes: private static FocusListener focusHandler = new FocusHandler(); combo.setEditable(true); combo.addFocusListener(focusHandler); ###@###.### 2002-05-30

SUGGESTED FIX ------- BasicComboBoxUI.java ------- 467a468,471 > if (comboBox.isEditable() && editor != null) { > editor.requestFocus(); > } > ###@###.### 2002-05-24

EVALUATION Yup this is a bug all right. It's still in 1.4 and 1.4.1 beta. A quick solution is to add a block to the BasicComboBoxUI.FocusHandler which will request the focus on the editor in the focusGained method call. See suggested fix. ###@###.### 2002-05-24