Modal JDialog 在 Solaris CDE 上消失在父级后面
我的代码包含一个 JFrame,它在执行某个操作后显示一个非模式 JDialog。用户需要将一个对象从 JFrame 拖到 JDialog 中。我遇到的问题仅出现在 Solaris CDE(通用桌面环境)上:打开 JDialog 将窗口正确定位在框架顶部。用户单击框架后,对话框在其后面消失,迫使用户重新定位框架以将其放在 JDialog 旁边。预期的行为是 JDialog 保持在父框架的顶部。
下面的代码演示了这种情况:
public class MyFrame extends JFrame
{
public MyFrame()
{
JButton btn = new JButton("Push me");
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
JDialog dialog = new JDialog(MyFrame.this);
dialog.getContentPane().add(new JLabel("I'm a dialog!!!"));
dialog.setAlwaysOnTop(true);
dialog.setVisible(true);
}
});
getContentPane().add(btn);
pack();
}
public static void main(String args[])
{
MyFrame frame = new MyFrame();
frame.setVisible(true);
}
}
在 Solaris 以及 Windows 和 Linux (GNOME) 上运行任何其他窗口管理器时,不会出现此问题。类似的问题已经被问过一段时间了(如何使无模式对话框在 Solaris CDE 中保持在其父级之上),但该问题仍未解决。
My code contains a JFrame which after a certain action, shows a non-modal JDialog. The user is expected to drag an object from the JFrame into the JDialog. The issue I'm having is only showing up on Solaris CDE (Common Desktop Environment): opening JDialog correctly positions the window on top of the frame. After the user clicks on the frame, dialog disappears behind it forcing the user to re-position the frame to put it besides JDialog. The expected behavior is for the JDialog to remain on top of the parent frame.
The following code demonstrates the situation:
public class MyFrame extends JFrame
{
public MyFrame()
{
JButton btn = new JButton("Push me");
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
JDialog dialog = new JDialog(MyFrame.this);
dialog.getContentPane().add(new JLabel("I'm a dialog!!!"));
dialog.setAlwaysOnTop(true);
dialog.setVisible(true);
}
});
getContentPane().add(btn);
pack();
}
public static void main(String args[])
{
MyFrame frame = new MyFrame();
frame.setVisible(true);
}
}
This problem is not when running any other window manager on solaris as well as windows and linux (GNOME). A similar question has been asked some time ago (How to make modeless dialog stay on top of its parent in Solaris CDE), but it remains unresolved.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JFrame
和JDialog
都继承了以下Window
便捷方法:toFront() 和 toBack(),尽管JDialog
从继承了后者对话框
。无论如何,尝试将其中任何一个与 结合使用WindowListener 通过侦听以下事件: windowActivated(WindowEvent e) 和 windowDeactivited(WindowEvent e)。编辑:
这是别人的
Both
JFrame
andJDialog
inherit the followingWindow
convenience methods: toFront() and toBack(), althoughJDialog
inherits the latter fromDialog
. Anyway, try using either of those in combination with a WindowListener by listening for the following events: windowActivated(WindowEvent e) and windowDeactivited(WindowEvent e).Edit:
This what someone else suggested,