-
Bug
-
Resolution: Fixed
-
P4
-
1.4.0
-
beta2
-
x86
-
windows_2000
Name: bsC130419 Date: 06/25/2001
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)
1. When focus goes from a JTextField to a JMenu, the text field receives a
temporary focus lost event but receives a permanent focus gained event.
As the focus lost event was temporary, shouldn't the focus gained event be also
temporary?
Example:
Execute example program.
Press Alt-F (focus goes from field 1 to menu) -> temporary focus lost.
Press Escape (or Enter) focus goes back to field 1 -> permanent focus gained.
Event history:
field 1.focusLost(e) temporary: true, to:javax.swing.JPopupMenu
field 1.focusGained(e) temporary: false, from:javax.swing.JPopupMenu
2. In a frame with at least two text fields, going from the second text field
to the menu and back results (when focus goes back to the second field) in a
focus gained and focus lost going to the first field before focus goes to the
second field.
Example:
Execute example program.
Click/Press tab so that focus goes to field 2.
Press Alt-F/Open menu -> field 2 receives a focus lost event.
Press Escape (or Enter) -> focus goes back to text field 1 and only then to
field 2.
Event history:
field 2.focusLost(e) temporary: true, to:javax.swing.JPopupMenu
field 1.focusGained(e) temporary: false, from:javax.swing.JPopupMenu
field 1.focusLost(e) temporary: false, to:field 2
field 2.focusGained(e) temporary: false, from:field 1
Example program:
/* Test2.java */
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTextField;
public class Test2 extends JFrame {
public Test2() {
JTextField field1 = new JTextField("Text field 1");
field1.setName("field 1");
field1.addFocusListener(new TextFieldFocusListener());
JTextField field2 = new JTextField("Text field 2");
field2.setName("field 2");
field2.addFocusListener(new TextFieldFocusListener());
getContentPane().setLayout(new FlowLayout());
getContentPane().add(field1);
getContentPane().add(field2);
JMenu menu = new JMenu("File");
menu.setName("File");
menu.setMnemonic('F');
JMenuItem menuItem = new JMenuItem("About");
menuItem.setName("About");
menu.add(menuItem);
JMenuBar menuBar = new JMenuBar();
menuBar.setName("menuBar");
menuBar.add(menu);
setJMenuBar(menuBar);
}
private class TextFieldFocusListener implements FocusListener {
public void focusGained(FocusEvent event) {
Component field = event.getComponent();
Component other = event.getOppositeComponent();
String sother = (other == null) ? "null" :
((other.getName() != null) ? other.getName() : other.getClass().getName());
System.out.println(field.getName() + ".focusGained(e)
temporary: " + event.isTemporary() + ", from:" + sother);
}
public void focusLost(FocusEvent event) {
Component field = event.getComponent();
Component other = event.getOppositeComponent();
String sother = (other == null) ? "null" :
((other.getName() != null) ? other.getName() : other.getClass().getName());
System.out.println(field.getName() + ".focusLost(e)
temporary: " + event.isTemporary() + ", to:" + sother);
}
}
public static void main(String[] args) {
Test2 test2 = new Test2();
test2.setDefaultCloseOperation(EXIT_ON_CLOSE);
test2.pack();
test2.setLocation(100, 50);
test2.setVisible(true);
}
}
// class Test2
(Review ID: 127247)
======================================================================