2011-06-14 46 views
0

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

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

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

回答

-1

它看起來像一個「寫一次,隨處運行」的java範例中的錯誤。如果是包含Windows 7,那麼您可以聯繫Oracle並填寫錯誤報告。

Regards, Stéphane

相關問題