簡體   English   中英

圖標化的 JFrame 在 win 7 任務欄點擊后顯示模態 JDialog

[英]Iconified JFrame showing behind modal JDialog on win 7 taskbar click

我最初在 Win XP 上開發了以下代碼。 當您單擊 XP 任務欄中的程序圖標時,父框架保持圖標化,JDialog 返回焦點,這是我想要的行為。 但是,當在 Win 7 上單擊程序的任務欄圖標時,父 JFrame 將其 state 更改回正常並顯示在應用程序模式 JDialog 后面。 我嘗試覆蓋 JFrame 的 setExtendedState() 方法來攔截框架的 state 更改,但沒有成功。

是否有解決方法,或者我的邏輯是否存在我需要解決的缺陷?

import java.awt.*;

import javax.swing.JDialog;
import javax.swing.JFrame;

public class TestLogin extends JFrame {

public TestLogin() {
    this.setSize(300, 300);
    iconify(this);
    setLocationRelativeTo(null);
    this.setTitle("I'm a Frame!");
    this.setVisible(true);
    LoginScreen login = new LoginScreen(this);
}

public static void main(String [] args) {

    TestLogin frame = new TestLogin();  
}

public static void iconify(Frame frame) {
    int state = frame.getExtendedState();

    // Set the iconified bit
    state |= Frame.ICONIFIED;

    // Iconify the frame
    frame.setExtendedState(state);
}

public static void deiconify(Frame frame) {
    int state = frame.getExtendedState();

    // Clear the iconified bit
    state &= ~Frame.ICONIFIED;
    // Deiconify the frame
    frame.setExtendedState(state);
}


public class LoginScreen extends JDialog {

    private JFrame root;

    public LoginScreen(JFrame root) {
        super(root);
        this.root = root;
        setLocationRelativeTo(null);
        this.setTitle("I'm a Dialog!");
        setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
        this.setSize(200, 200);
        setVisible(true);
    }
}
}

它看起來像是“一次編寫,隨處運行”的 java 范例中的一個錯誤。 如果這包括 windows 7,那么您可以聯系 oracle 並填寫錯誤報告。

問候, 斯蒂芬

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM