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