javaswingjdialogeclipse-virgo

Spring/Virgo - java swing: JDialog starts behind other windows


I have a service running on Virgo that occasionally needs to prompt the user and get some feedback. I've created a class that extends the JDialog class:

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
}

And another class that creates a new JFrame and popups up the dialog:

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);
   }
}

Everything works out ok except when the JDialog pops up, it starts in the background behind all my other windows (other apps). The problem is that since the JDialog doesn't create a taskbar entry, the dialog goes unnoticed unless all the existing windows are minimised. I understand that this happens because the GUI is started from virgo but I was wondering if it's possible to bring it forward so it starts in the foreground. I noticed that the same thing happens when I use JOptionPane. All JOptionPane messages appear in the background. That's only when the GUI is started from a virgo service. I don't have that issue if I run the GUI as a standalone application.


Solution

  • Try using: setAlwaysOnTop(true);

    In your case:

    dialog.setAlwaysOnTop(true);