[英]New window appears sandwiched between parent and child JFrame/JDialog
來自其他進程的新窗口將在重點突出的JDialog子級后面但在JDialog父級前面打開。 我希望新窗口出現在孩子面前。 這些窗口均未聲明始終位於最上面。
圖片
實際訂單
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)
此問題僅在以下情況下發生
如果在下面的示例中該窗口稍微向右打開(更改為newWindow.setBounds(**370**, 20, 0, 200)
),則該窗口不在始終位於頂部的窗口后面,則它顯示在前面的孩子。
明確地說,此問題發生在三個單獨的應用程序之間,但是為簡單起見,我在下面將其重新創建為單個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
碼
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.