java - Spring /处女座 - java swing : JDialog starts behind other windows

标签 java swing jdialog eclipse-virgo

我有一个在 Virgo 上运行的服务,偶尔需要提示用户并获取一些反馈。 我创建了一个扩展 JDialog 类的类:

public class PPNDialog extends JDialog implements ActionListener, WindowListener{
    public PPNDialog(JFrame frame, String title){
        super(frame, title, true);
        ... //rest of dialog initialisation code
    }
    ... //(other methods
}

另一个类创建一个新的 JFrame 并弹出对话框:

public class GUIStarter {
   JFrame frame;
   public GUIStarter(){
        this.initialise();
        dialog = new PPNDialog(this.frame, "");
        dialog.setVisible(true);
   }
   private void initialise() {
        frame = new JFrame();
        frame.setBounds(100, 100, 450, 300);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
   }
}

一切正常,除了 JDialog 弹出时,它在我所有其他窗口(其他应用程序)后面的后台启动。问题是,由于 JDialog 不创建任务栏条目,因此除非最小化所有现有窗口,否则该对话框不会被注意到。 我知道发生这种情况是因为 GUI 是从处女座启动的,但我想知道是否可以将其向前推进,以便它在前台启动。我注意到当我使用 JOptionPane 时也会发生同样的事情。所有 JOptionPane 消息都显示在后台。仅当 GUI 从 virgo 服务启动时才会出现这种情况。如果我将 GUI 作为独立应用程序运行,则不会出现此问题。

最佳答案

尝试使用:setAlwaysOnTop(true);

就您而言:

dialog.setAlwaysOnTop(true);

关于java - Spring /处女座 - java swing : JDialog starts behind other windows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24844369/

相关文章:

java - 在 swing 中居中组件并调整 JFrame 大小

java - JDialog 位于屏幕中心,而不是 JApplet 所需的中心

Java-Slick2D/lwjgl 获取鼠标位置

java - Clojure 中是否有适用于 Java 函数的应用函数?

java - 使用 Jython 在 Spring Boot 应用程序中包含 Python 脚本失败 - 找不到模块

Java Swing 事件冒泡/捕获

java - 复选框节点树

java - 使用许多 jFrame

java - Java 中的 ModalDialog 阻塞

java - 如何将数组中的项目放入不同的复选框中?