-
Bug
-
Resolution: Unresolved
-
P3
-
6
-
Cause Known
-
x86
-
windows_xp
If we are calling Window.getMostRecentFocusOwner() method in the windowGainedFocus() method of window focus listener, added to JFrame, Window.getMostRecentFocusOwner() returns null. I think, this is not OK.
Then the test program is opened, and focus is moving out from the test program window, output is not null. But then focus is moved to the test program window from outside, for example, from another application to one of two text fields, the output value, that is the result of Window.getMostRecentFocusOwner(), is null.
Here is the test program:
-----------------------BEGIN SOURCE--------------------------------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class awttest {
public static void main(String[] args) {
final JFrame frame = new JFrame("Test");
frame.setLayout(new java.awt.FlowLayout());
JTextField tf1 = new JTextField(10);
JTextField tf2 = new JTextField(10);
Container cp = frame.getContentPane();
cp.add(tf1);
cp.add(tf2);
frame.addWindowFocusListener(new WindowAdapter() {
public void windowGainedFocus(WindowEvent e) {
System.out.println(frame.getMostRecentFocusOwner());
}
public void windowLostFocus(WindowEvent e) {
System.out.println(frame.getMostRecentFocusOwner());
}
});
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
-----------------------END SOURCE----------------------------------------
###@###.### 2004-12-21 19:48:14 GMT
Then the test program is opened, and focus is moving out from the test program window, output is not null. But then focus is moved to the test program window from outside, for example, from another application to one of two text fields, the output value, that is the result of Window.getMostRecentFocusOwner(), is null.
Here is the test program:
-----------------------BEGIN SOURCE--------------------------------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class awttest {
public static void main(String[] args) {
final JFrame frame = new JFrame("Test");
frame.setLayout(new java.awt.FlowLayout());
JTextField tf1 = new JTextField(10);
JTextField tf2 = new JTextField(10);
Container cp = frame.getContentPane();
cp.add(tf1);
cp.add(tf2);
frame.addWindowFocusListener(new WindowAdapter() {
public void windowGainedFocus(WindowEvent e) {
System.out.println(frame.getMostRecentFocusOwner());
}
public void windowLostFocus(WindowEvent e) {
System.out.println(frame.getMostRecentFocusOwner());
}
});
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
-----------------------END SOURCE----------------------------------------
###@###.### 2004-12-21 19:48:14 GMT