java - Modal JDialog 在 Solaris CDE 上消失在父级后面

标签 java swing solaris

我的代码包含一个 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) 上运行任何其他窗口管理器时,不会出现此问题。类似的问题不久前已经被问过(How to make modeless dialog stay on top of its parent in Solaris CDE),但仍未解决。

最佳答案

JFrameJDialog 都继承了以下 Window 便捷方法:toFront()toBack() ,尽管 JDialogDialog 继承了后者。无论如何,尝试将其中任何一个与 WindowListener 结合使用。通过监听以下事件:windowActivated(WindowEvent e)windowDeactivited(WindowEvent e) .

编辑:

这是别人的suggested ,

attach a focus listener on the JDialog and when it loses focus, move it to the front of all the other windows. This will cause flickering and works pretty horribly.

关于java - Modal JDialog 在 Solaris CDE 上消失在父级后面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5748090/

相关文章:

java - java中printf和println的区别?

仅 VPN 网站上的 Java HTTP 请求

java - 在 Java Swing 中缩放 JPanel

java - 在 Swing 面板上绘制多个矩形

java - 使用复杂的 TableCellRenderer 在 JTable 中格式化来自 JDBC 的数据

c++ - 使用 gcc 32 位编译,作为带有 -m64 的 64 位程序

c - 在 Solaris/Linux 中释放分配的内存

java - 有没有办法评估/衡量Java代码的效率

c++ - 在 solaris 上创建和使用动态共享库

java - 在 Linux 上安装 Java EE SDK 时出错