all. i want to minimize my jframe with setExtendedState(JFrame.ICONIFIED), in most case, it works properly, but when it does not work when i lock my os(windows XP) screen with WIN+L.My wimple code are as follows:
import javax.swing.JDialog;
import javax.swing.JFrame;
public class FrameTest extends JFrame {
public static FrameTest ft = new FrameTest();
public static void main(String[] args)
{
FrameTest.ft.setVisible(true);
FrameTest.ft.setLocation(300, 300);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JDialog dlg = new JDialog( ft, "xxx", true );
ft.setExtendedState(JFrame.ICONIFIED);
dlg.setVisible(true);//if not have this line, it works also in screen lock case
}开发者_JAVA技巧
}
Any help will be appreciated.
It could me that you are manipulating Swing components from the main thread instead of the Event Dispatch Thread. Try wrapping the contents of main
in:
public static void main(String[] args)
{
SwingUtilities.invokeLater(new Rennable() {
@Override
void run() {
FrameTest.ft.setVisible(true);
FrameTest.ft.setLocation(300, 300);
}
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
SwingUtilities.invokeLater(new Rennable() {
@Override
void run() {
JDialog dlg = new JDialog( ft, "xxx", true );
ft.setExtendedState(JFrame.ICONIFIED);
dlg.setVisible(true);case
}
}
If that doesn't help, try splitting the second invokeLater
block into:
SwingUtilities.invokeLater(new Rennable() {
@Override
void run() {
ft.setExtendedState(JFrame.ICONIFIED);
}
SwingUtilities.invokeLater(new Rennable() {
@Override
void run() {
JDialog dlg = new JDialog( ft, "xxx", true );
dlg.setVisible(true);case
}
That gives Swing a chance to respond to the iconification before handing off control to the dialog.
精彩评论