-
Bug
-
Resolution: Fixed
-
P3
-
1.4.0
-
beta3
-
generic
-
generic
Name: gm110360 Date: 10/03/2001
Windows
java version "1.4.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b65)
Java HotSpot(TM) Client VM (build 1.4.0-beta-b65, mixed mode)
Linux
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)
package test;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/*
* To replicate this error that occurs, merely try and click the arrow box
* or just use the down arrow key on the keyboard. This will cause the dropdown
* to appear.
*
* In the frame1:
* On the first jBox, it works fine, you can scroll through, and still type
* what you want in the box. On the second combo box, when doing the same
* behavior, the editor loses the focus completely, as does the JFrame itself.
*
* Frame2 works similarly, but I've added a focus listener to display what
* happens when you try and hide the popup automatically. It shows how the
* second dropdown when it goes off the screen returns the focus to the
* editor component. putting "showPopup()" in the method "focusGained"
* would then cause an infinite loop, as the popup would gain the focus,
* when it goes offscreen. The JFrame would thus lose the focus, calling
* focusLost. focusLost would hide the popup, which returns control
* back to the editor component, calling focusGained, which pops the window,
* ad infinitum.
*
*
*/
public class TestCombo extends JFrame{
public JComboBox jBox1 = new JComboBox();
public JComboBox jBox2 = new JComboBox();
TestCombo(String frameName) {
super(frameName);
jBox1.addItem("TEST");
jBox1.addItem("TEST1");
jBox1.addItem("TEST2");
jBox1.addItem("TEST3");
jBox1.addItem("TEST4");
jBox2.addItem("2TEST");
jBox2.addItem("2TEST1");
jBox2.addItem("2TEST2");
jBox2.addItem("2TEST3");
jBox2.addItem("2TEST4");
jBox1.setEditable(true);
jBox2.setEditable(true);
jBox1.setBounds(0,0,200,20);
jBox2.setBounds(0,20,200,20);
setSize(400,400);
getContentPane().add(jBox1,BorderLayout.NORTH);
getContentPane().add(jBox2,BorderLayout.SOUTH);
show();
}
public static void main(String args[]) {
final TestCombo tb = new TestCombo("Frame1");
final TestCombo tb2 = new TestCombo("Frame2");
//this shows even more, on an errline how the focus has been lost totally
tb2.jBox1.getEditor().getEditorComponent().addFocusListener(new FocusListener() {
public void focusLost(FocusEvent fe) {
System.err.println("Focus lost!");
tb2.jBox1.hidePopup();
}
public void focusGained(FocusEvent fe) {
System.err.println("Focus gained!");
}
});
tb2.jBox2.getEditor().getEditorComponent().addFocusListener(new FocusListener() {
public void focusLost(FocusEvent fe) {
System.err.println("Focus lost!");
tb2.jBox2.hidePopup();
}
public void focusGained(FocusEvent fe) {
System.err.println("Focus gained!");
}
});
}
}
(Review ID: 133079)
======================================================================