-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
6
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
In the following code, although JPanel is focusable ( JPanel().isFocusable() == true), I have to call setFocusable() or the focus listener will not be called, why is it so strange ?
class TestJPanel {
public static void main(String[] args){
JFrame frame = new JFrame("test");
JPanel panel = new JPanel();
System.out.println("JPanel focusable ? " + panel.isFocusable());
// although JPanel is focusable, the below line is necessary
// or focus listener is not called, why ???
panel.setFocusable(true);
panel.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
System.out.println("focusGained " + e);
}
public void focusLost(FocusEvent e) {
System.out.println("focusLost " + e);
}
});
frame.add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setBounds(100,100,400,300);
frame.setVisible(true);
}
}
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
compile the code, run it, click mouse button. the JPanel can get focus only when setFocusable is called.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
If isFocusable() is true, setFocusable(true) need not be called again.
ACTUAL -
setFocusable() must be called for JPanel to gain focus even JPanel.isFocusable() is true
REPRODUCIBILITY :
This bug can be reproduced always.
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
In the following code, although JPanel is focusable ( JPanel().isFocusable() == true), I have to call setFocusable() or the focus listener will not be called, why is it so strange ?
class TestJPanel {
public static void main(String[] args){
JFrame frame = new JFrame("test");
JPanel panel = new JPanel();
System.out.println("JPanel focusable ? " + panel.isFocusable());
// although JPanel is focusable, the below line is necessary
// or focus listener is not called, why ???
panel.setFocusable(true);
panel.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
System.out.println("focusGained " + e);
}
public void focusLost(FocusEvent e) {
System.out.println("focusLost " + e);
}
});
frame.add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setBounds(100,100,400,300);
frame.setVisible(true);
}
}
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
compile the code, run it, click mouse button. the JPanel can get focus only when setFocusable is called.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
If isFocusable() is true, setFocusable(true) need not be called again.
ACTUAL -
setFocusable() must be called for JPanel to gain focus even JPanel.isFocusable() is true
REPRODUCIBILITY :
This bug can be reproduced always.