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

发布于 2024-11-01 08:12:28 字数 839 浏览 7 评论 0原文

全部。 我想用 setExtendedState(JFrame.ICONIFIED) 最小化我的 jframe,在大多数情况下,它可以正常工作,但是当我用 WIN+L 锁定我的操作系统(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 
    }   
}

任何帮助将不胜感激。

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

Any help will be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何时共饮酒 2024-11-08 08:12:28

我可能认为您正在从主线程而不是事件调度线程操作 Swing 组件。尝试将 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 
     }   
}

如果这没有帮助,请尝试将第二个 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 
     }   

这使 Swing 有机会在移交之前响应图标化控制到对话框。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文