-
Bug
-
Resolution: Not an Issue
-
P3
-
1.4.2
-
x86
-
linux
FULL PRODUCT VERSION :
java version "1.4.2_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_06-b03)
Java HotSpot(TM) Client VM (build 1.4.2_06-b03, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux localhost.localdomain 2.6.10-1.8_FC2 #1 Mon Jan 10 14:46:18 EST 2005 i686 athlon i386 GNU/Linux
EXTRA RELEVANT SYSTEM CONFIGURATION :
I'm using FedoreCore 2 Linux with GNOME 2.6. desktop environment. Everything is installed by default.
A DESCRIPTION OF THE PROBLEM :
I've found that in many Java applications, modal dialogs which are shown on parent frame do not get keyboard focus sometimes. It happens in GNOME environment with metacity windows manager. Also I'd like to mention that dialogs do not get focus sporadically, so it's not reproducible everytime.
I've wrotten small example wich perfectly demonstrate what I'm talking about.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Compile and run attached sample
2. Sample code shows frame and starts to open and close modal dialogs.
3. After some iterations (it could be 10 or 100) you'll see that modal dialog appears and it doesn't have keyboard focus. Moreover, parent frame which is locked by this modal dialog _has_ focus! You'll see that "Show Dialog" button has focus border and there will be output in console which says that parent frame is an active window! It's wrong.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
1. Modal dialog should always get focus,
2. Locked frame should never be an active window
ACTUAL -
1. Modal dialog doesn't get input focus
2. Locked frame is reported as active window
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
/**
* @author Vladimir Kondratyev
*/
public class test {
private static void doTest(){
final JFrame frame = new JFrame();
Container contentPane = frame.getContentPane();
JButton button = new JButton("Open Dialog");
contentPane.add(button);
button.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
final JDialog dialog = new JDialog(frame, "Modal Dialog", true);
Container contentPane = dialog.getContentPane();
JTextField textField = new JTextField("Some text");
contentPane.add(textField);
textField.addFocusListener(
new FocusAdapter() {
public void focusGained(FocusEvent e) {
if(!e.isTemporary()){
dialog.dispose();
}
}
}
);
dialog.pack();
dialog.show();
}
}
);
frame.pack();
frame.show();
while(true){
button.doClick();
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(
new Runnable() {
public void run() {
doTest();
}
}
);
Thread focusPrinter = new Thread(){
public void run() {
while (true) {
Window activeWindow = FocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
System.out.println(activeWindow);
try {
Thread.sleep(200);
} catch (InterruptedException e) { }
}
}
};
focusPrinter.start();
}
}
---------- END SOURCE ----------
###@###.### 2005-03-10 11:04:50 GMT
java version "1.4.2_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_06-b03)
Java HotSpot(TM) Client VM (build 1.4.2_06-b03, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux localhost.localdomain 2.6.10-1.8_FC2 #1 Mon Jan 10 14:46:18 EST 2005 i686 athlon i386 GNU/Linux
EXTRA RELEVANT SYSTEM CONFIGURATION :
I'm using FedoreCore 2 Linux with GNOME 2.6. desktop environment. Everything is installed by default.
A DESCRIPTION OF THE PROBLEM :
I've found that in many Java applications, modal dialogs which are shown on parent frame do not get keyboard focus sometimes. It happens in GNOME environment with metacity windows manager. Also I'd like to mention that dialogs do not get focus sporadically, so it's not reproducible everytime.
I've wrotten small example wich perfectly demonstrate what I'm talking about.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Compile and run attached sample
2. Sample code shows frame and starts to open and close modal dialogs.
3. After some iterations (it could be 10 or 100) you'll see that modal dialog appears and it doesn't have keyboard focus. Moreover, parent frame which is locked by this modal dialog _has_ focus! You'll see that "Show Dialog" button has focus border and there will be output in console which says that parent frame is an active window! It's wrong.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
1. Modal dialog should always get focus,
2. Locked frame should never be an active window
ACTUAL -
1. Modal dialog doesn't get input focus
2. Locked frame is reported as active window
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
/**
* @author Vladimir Kondratyev
*/
public class test {
private static void doTest(){
final JFrame frame = new JFrame();
Container contentPane = frame.getContentPane();
JButton button = new JButton("Open Dialog");
contentPane.add(button);
button.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
final JDialog dialog = new JDialog(frame, "Modal Dialog", true);
Container contentPane = dialog.getContentPane();
JTextField textField = new JTextField("Some text");
contentPane.add(textField);
textField.addFocusListener(
new FocusAdapter() {
public void focusGained(FocusEvent e) {
if(!e.isTemporary()){
dialog.dispose();
}
}
}
);
dialog.pack();
dialog.show();
}
}
);
frame.pack();
frame.show();
while(true){
button.doClick();
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(
new Runnable() {
public void run() {
doTest();
}
}
);
Thread focusPrinter = new Thread(){
public void run() {
while (true) {
Window activeWindow = FocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
System.out.println(activeWindow);
try {
Thread.sleep(200);
} catch (InterruptedException e) { }
}
}
};
focusPrinter.start();
}
}
---------- END SOURCE ----------
###@###.### 2005-03-10 11:04:50 GMT
- relates to
-
JDK-4821469 Focus does not transfer properly to JOptionPane with Red Hat 8 and Gnome
-
- Open
-