简体   繁体   English

为什么在Windows屏幕锁定时setExtendedState(JFrame.ICONIFIED)不起作用?

[英]Why setExtendedState(JFrame.ICONIFIED)does not work while windows screen locked?

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: 我想用setExtendedState(JFrame.ICONIFIED)最小化我的jframe,在大多数情况下,它可以正常工作,但是当我用WIN + L锁定OS(Windows XP)屏幕时却无法正常工作,我的wimple代码如下:

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 
    }   
}

Any help will be appreciated. 任何帮助将不胜感激。

It could me that you are manipulating Swing components from the main thread instead of the Event Dispatch Thread. 我可能是从主线程而不是事件调度线程来操纵Swing组件。 Try wrapping the contents of main in: 尝试将main的内容包装在:

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: 如果那没有帮助,请尝试将第二个invokeLater块拆分为:

    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. 这样一来,Swing就有机会在将控件移交给对话框之前对图标化做出响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM