JOptionPane显示在父JFrame的后面 [英] JOptionPane displays behind the parent JFrame

查看:116
本文介绍了JOptionPane显示在父JFrame的后面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows操作系统上创建了一个swing应用程序.我的JDialog之一(其窗口为parentJFrame)显示了JOptionPane.
JOptionPane.showMessageDialog(parentJFrame, "I am a JOption");.

I created a swing application on Windows OS. One of my JDialog (whose window is parentJFrame) shows a JOptionPane.
JOptionPane.showMessageDialog(parentJFrame, "I am a JOption"); .

在运行时,parentJFrame setAlwaysOnTop(true).即使已将alwaysOnTop-TRUE设置为JOptionPane,它也会出现在Windows OS的parentJFrame上.但是当我在Linux OS上运行它时,JOptionPane会显示在parentJFrame后面.(可能是因为parentJFrame alwyasOnTop是true ,但是JRE如何针对不同的OS以不同的方式运行相同的应用程序?)如何在Linux中将其放在parentJFrame的顶部?请紧急..
当'alwaysOnTop-true'组件显示JOptionPane时,JOptionPane出现在Linux中该组件的后面..:(.但这在Windows OS中处理得很好.JOptionPane显示在设置为'alwaysOnTop-true'的组件顶部.似乎有冲突,在Linux OS的桌面屏幕上显示组件.我不确定.但是我想是这样.

At the run time, the parentJFrame setAlwaysOnTop(true) . Even though it has set alwaysOnTop-TRUE, the JOptionPane appeares on the parentJFrame on Windows OS. but When I ran it on Linux OS,JOptionPane displays behind the parentJFrame.(May be the reason is that parentJFrame alwyasOnTop is true, but how JRE runs the same application in different ways for diffrent OS s ?) How can I get it on the top of parentJFrame in Linux.? This is urgent please..
When a 'alwaysOnTop-true' component shows a JOptionPane, JOptionPane appears behind the component in Linux.. :( . But this handled well in Windows OS. JOptionPane is showed on the top of the component which is set 'alwaysOnTop-true' . It seemed that, there is a conflict Showing components on the desktop screen in Linux OS.. I m not sure so. But I guess it.

  • Linux操作系统具有Oracle JDK和JRE 7

推荐答案

您在Linux上看到的行为符合API规范.这就是窗口的说法.setAlwaysOnTop():

The behaviour you see on Linux is in accordance with the API specification. This is what it says for Window.setAlwaysOnTop():

如果存在多个始终位于最上层的窗口,则它们的相对顺序是不确定的,并且取决于平台.

If there are multiple always-on-top windows, their relative order is unspecified and platform dependent.

还有:

始终位于最上层的窗口拥有的所有窗口都继承此状态,并自动变为始终处于最上层.

All windows owned by an always-on-top window inherit this state and automatically become always-on-top.

这将解释为什么位于JOptionPane核心的JDialog也具有总是在最前面"的状态.似乎在Windows上它偶然会按预期运行,但实际上您是在要求Swing做一些不可能的事情:在总是在其他窗口上方"显示父级,并在其上方显示对话框.

Which would explain why the JDialog that's at the heart of JOptionPane also has "always on top" status. Seems that on Windows by chance it works as you expected, but really you're asking Swing to do something impossible: To show the parent "always above other windows", but also to show the dialog on top of it.

这是一种可能的解决方法:将对话框放置在父对话框旁边,以便当它在z轴上位于对话框下方时,用户仍会看到它:

Here's a possible workaround: Place the dialog next to the parent, so that while it's under it on the z-axis, the user will still see it:

JDialog dialog = new JOptionPane("Message").createDialog(parent, "Title");
Point dialogLoc = dialog.getLocation();
Point parentLoc = parent.getLocation();
dialog.setLocation(parentLoc.x + parent.getWidth(), dialogLoc.y);
dialog.setVisible(true);

请注意,没有单一的"Linux OS",尤其是在窗口管理方面-有很多不同的桌面环境和窗口管理器,它们在窗口排序和可见性方面的行为方式大不相同,通常是故意的

Do note that there is no single "Linux OS", especially when it comes to window management - there are lots of different desktop environments and window managers that behave in widely different ways when it comes to window ordering and visibility, often deliberately.

这篇关于JOptionPane显示在父JFrame的后面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆