簡體   English   中英

出現在父級和子級JFrame / JDialog之間的新窗口

[英]New window appears sandwiched between parent and child JFrame/JDialog

來自其他進程的新窗口將在重點突出的JDialog子級后面但在JDialog父級前面打開。 我希望新窗口出現在孩子面前。 這些窗口均未聲明始終位於最上面。

圖片

  • 看到應用程序3在應用程序2窗口之間
  • 沒關系,它位於應用1后面-始終位於最前面,這是預期的

應用程式2視窗之間3

實際訂單

JDialog (App 1 - always on top)
JFrame (App 2 non modal dialog child of app 2 main)
JDialog (App 3) <=== new window should appear on top of app 2
JFrame (App 2 - main window)

預期訂單

JDialog (App 1 - always on top)
JDialog (App 3) <=== new window should appear on top of app 2
JFrame (App 2 non modal dialog child of app 2 main)
JFrame (App 2 - main window)

此問題僅在以下情況下發生

  • 有一個來自另一個進程的現有窗口,該窗口被聲明為永遠在最上面,不必是Java,我只是在下面的示例中使用了Java-但是,如果您選擇永遠在最上面,例如Firefox,gnome,也會發生問題-終端等
  • 在始終位於頂部的應用程序后面的位置打開的新窗口。 同樣,不必是Java應用程序,在gnome-terminal的Firefox中也可以重復使用。
  • Redhat Linux6。在Ubuntu 16.04或Windows 7上不可重復

如果在下面的示例中該窗口稍微向右打開(更改為newWindow.setBounds(**370**, 20, 0, 200) ),則該窗口不在始終位於頂部的窗口后面,則它顯示在前面的孩子。

3在2以上打開

明確地說,此問題發生在三個單獨的應用程序之間,但是為簡單起見,我在下面將其重新創建為單個Java應用程序。

public class Combined {
    public static void main(String[] args) throws Exception {

        JFrame aot = new JFrame("App 1 - always on top");
        aot.setAlwaysOnTop(true);
        aot.setBounds(50, 50, 300, 40);
        aot.setVisible(true);

        JFrame frame = new JFrame("App 2 - main window");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setBounds(100, 100, 300, 200);
        frame.setVisible(true);

        JDialog child = new JDialog(frame, "App 2 - non-modal child dialog (child)");
        child.setBounds(150, 150, 300, 200);
        child.setVisible(true);

        Thread.sleep(1000);
        JFrame newWindow = new JFrame("App 3");
        newWindow.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        newWindow.setBounds(200, 20, 300, 200);
        // newWindow.setBounds(370, 20, 300, 200);

        newWindow.setVisible(true);
    }
}

是否可以將任何選項應用於JDialog子級,以便允許Windows顯示在其上方。 背景是我正在開發“ app 2”應用程序,所有其他部分和Redhat Linux安裝都由其他第三方管理,因此不能輕易更改。

嘗試使用嚴格/智能的窗口管理器選項,但行為沒有差異

gconftool-2 --set /schemas/apps/metacity/general/focus_new_windows --type string smart
gconftool-2 --set /schemas/apps/metacity/general/focus_new_windows --type string strict

哈克解決方案

  • 顯示,隱藏,然后再次顯示App 3窗口。 在這種情況下,它會正確顯示在“ App 2 child”上方,盡管這會引起明顯的閃爍

newWindow.setVisible(true);
newWindow.setVisible(false);
newWindow.setVisible(true);

總之,對於此Linux Windows管理特定問題,沒有好的解決方案。 所有可以做的就是從應用程序中清除始終位於頂部的窗口。 無論如何,這都是最佳實踐,但是在處理舊版代碼庫時卻很難。

絕望的唯一其他解決方案是執行setVisible()舞蹈。

newWindow.setVisible(true);
newWindow.setVisible(false);
newWindow.setVisible(true);

暫無
暫無

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

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