0

全て。jframe を setExtendedState(JFrame.ICONIFIED) で最小化したいのですが、ほとんどの場合は正常に動作しますが、OS(Windows XP) の画面を WIN+L でロックすると動作しない場合があります。私の 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 
    }   
}

どんな助けでも大歓迎です。

4

1 に答える 1

0

イベント ディスパッチ スレッドではなく、メイン スレッドから 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 
     }   
}

それでも解決しない場合は、2 番目の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 に与えられます。

于 2011-05-09T20:35:30.573 に答える