When dialog window displayed it does not focused if other window is active (i.e. you need to focus it by mouse pointer to be able to deal with it). How can I make a focus to displayed dialog?
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class GuiTest {
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
createAndShowGUI();
}
});
}
private static void createAndShowGUI() {
JFrame frame = new JFrame("frame");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setAlwaysOnTop(true);
JOptionPane.showMessageDialog(frame, "test info", "test header",
JOptionPane.INFORMATION_MESSAGE);
//frame.toFront();
//frame.requestFocus();
frame.dispose(); // When a frame is disposed, the exit action will be
// called.
}
}