[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-swing-dev
Subject:    <Swing Dev> Focus lost after minimize and restore a window on linux
From:       zhouyx () linux ! vnet ! ibm ! com (Sean Chou)
Date:       2011-06-13 10:58:34
Message-ID: BANLkTik783EGONb23-EgnPO_W8F8-J3CgA () mail ! gmail ! com
[Download RAW message or body]

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");
super.setBackground(Color.gray);
 // set layout here.
setLayout(new FlowLayout());
 c = new JButton("JButton");
add(c);
 addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event) {
System.exit(0);
}
 public void windowActivated(WindowEvent event){
/* // Timing block
                                try {
Thread.sleep(10);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}*/
}
});
setSize(850, 360);
setVisible(true);
}
 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.

Observation:
Focus is lost.


Investigation:
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/swing-dev/attachments/20110613/73889d75/attachment.html 

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic