-
Bug
-
Resolution: Not an Issue
-
P3
-
1.5.1
-
generic
-
generic
According to JDK 1.4 and JDK1.5 spec: "
public void setFocusableWindowState(boolean focusableWindowState)
Sets whether this Window can become the focused Window if it meets the other requirements outlined in isFocusableWindow. If this Window's focusable Window state is set to false, then isFocusableWindow will return false....
public final boolean isFocusableWindow()
Returns whether this Window can become the focused Window, that is, whether this Window or any of its subcomponents can become the focus owner. For a Frame or Dialog to be focusable, its focusable Window state must be set to true. For a Window which is not a Frame or Dialog to be focusable, its focusable Window state must be set to true, its nearest owning Frame or Dialog must be showing on the screen, and it must contain at least one Component in its focus traversal cycle. If any of these conditions is not met, then neither this Window nor any of its subcomponents can become the focus owner.
"
In the following test sample code, the frame was first made focused, and then calling setFocusableWindowState(false) to make it non-focuablewindow.
The test expected that the component contained in the window will not gain the focus, and the window will not become the focused window.
===============================================================
import java.awt.*;
public class MyFocusTest extends AWTFocusBase {
public void checkCase1() {
KeyboardFocusManager current = KeyboardFocusManager.getCurrentKeyboardFocusManager();
try {
Component comp = new Button();
Frame frame = new Frame();
frame.setVisible(true);
moveFocusTo(frame);
System.out.println("Expecting frame is focused here: frame.isFocused(): "+frame.isFocused());
frame.add(comp);
frame.setFocusableWindowState(false);
System.out.println("expecting frame.isFocusableWindow() return false, got "+frame.isFocusableWindow());
startFocusTracking(comp);
comp.requestFocusInWindow();
if (verifyFocusGained(comp)) {
System.out.println("Unexpected comp gained the focus");
} else {
System.out.println("OKAY: comp did not gain the focus");
}
System.out.println("current focus owner: "+current.getFocusOwner());
System.out.println("current focused window: "+current.getFocusedWindow());
System.out.println("frame focused? "+frame.isFocused());
} catch (Exception e) {
System.out.println("exception thrown: "+e);
return;
}
}
public static void main(String[] args) {
MyFocusTest t = new MyFocusTest();
t.checkCase1();
}
=========================================================================
The result of running the above code on jdk 1.4 and jdk 1.5 as follow:
Expecting frame is focused here: frame.isFocused(): true
expecting frame.isFocusableWindow() return false, got false
OKAY: comp did not gain the focus
current focus owner: null
current focused window: java.awt.Frame[frame0,1,1,86x35,invalid,layout=java.awt.BorderLayout,title=,resizable,normal]
frame focused? true
The AWTFocusBase.java is attched
###@###.### 10/12/04 21:58 GMT
public void setFocusableWindowState(boolean focusableWindowState)
Sets whether this Window can become the focused Window if it meets the other requirements outlined in isFocusableWindow. If this Window's focusable Window state is set to false, then isFocusableWindow will return false....
public final boolean isFocusableWindow()
Returns whether this Window can become the focused Window, that is, whether this Window or any of its subcomponents can become the focus owner. For a Frame or Dialog to be focusable, its focusable Window state must be set to true. For a Window which is not a Frame or Dialog to be focusable, its focusable Window state must be set to true, its nearest owning Frame or Dialog must be showing on the screen, and it must contain at least one Component in its focus traversal cycle. If any of these conditions is not met, then neither this Window nor any of its subcomponents can become the focus owner.
"
In the following test sample code, the frame was first made focused, and then calling setFocusableWindowState(false) to make it non-focuablewindow.
The test expected that the component contained in the window will not gain the focus, and the window will not become the focused window.
===============================================================
import java.awt.*;
public class MyFocusTest extends AWTFocusBase {
public void checkCase1() {
KeyboardFocusManager current = KeyboardFocusManager.getCurrentKeyboardFocusManager();
try {
Component comp = new Button();
Frame frame = new Frame();
frame.setVisible(true);
moveFocusTo(frame);
System.out.println("Expecting frame is focused here: frame.isFocused(): "+frame.isFocused());
frame.add(comp);
frame.setFocusableWindowState(false);
System.out.println("expecting frame.isFocusableWindow() return false, got "+frame.isFocusableWindow());
startFocusTracking(comp);
comp.requestFocusInWindow();
if (verifyFocusGained(comp)) {
System.out.println("Unexpected comp gained the focus");
} else {
System.out.println("OKAY: comp did not gain the focus");
}
System.out.println("current focus owner: "+current.getFocusOwner());
System.out.println("current focused window: "+current.getFocusedWindow());
System.out.println("frame focused? "+frame.isFocused());
} catch (Exception e) {
System.out.println("exception thrown: "+e);
return;
}
}
public static void main(String[] args) {
MyFocusTest t = new MyFocusTest();
t.checkCase1();
}
=========================================================================
The result of running the above code on jdk 1.4 and jdk 1.5 as follow:
Expecting frame is focused here: frame.isFocused(): true
expecting frame.isFocusableWindow() return false, got false
OKAY: comp did not gain the focus
current focus owner: null
current focused window: java.awt.Frame[frame0,1,1,86x35,invalid,layout=java.awt.BorderLayout,title=,resizable,normal]
frame focused? true
The AWTFocusBase.java is attched
###@###.### 10/12/04 21:58 GMT