Focus lost after minimize and restore a window on linux

Sean Chou zhouyx at
Mon Jun 13 10:58:34 UTC 2011

Hi all,

    I found a bug about focus lost on linux. The testcase is as follows:

import java.awt.Color;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;

public class FocusTest extends Frame {
Component c;
public FocusTest() {
super("Single Frame --- AWT Frame");
 // set layout here.
setLayout(new FlowLayout());
 c = new JButton("JButton");
 addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event) {
 public void windowActivated(WindowEvent event){
/* // Timing block
                                try {
} catch (InterruptedException e) {
// TODO Auto-generated catch block
setSize(850, 360);
 public static void main(String[] args) {
new FocusTest();

Reproduce steps:
1. Run the testcase with java7 jre on Linux (ubuntu with unity or gnome and
RHEL6 are tested.)
2. Click "JButton" so it get the focus.
3. Minimize the window.
4. Restore the window with mouse click on task icon or with alt+tab.

Expected result:
The focus is still on JButton.

Focus is lost.

It seems a timing problem, if the "Timing block" is uncommented, the
testcase works well.
On my workstation, the minimal working sleep time is 5ms. If 3ms is used,
the testcase
fails too.

I think the focus must be restored, it is very important for GUI
applications. Can any body
give some suggestion?

Best Regards,
Sean Chou

More information about the core-libs-dev mailing list