[英]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.