我在 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 是从 virgo 开始的,但我想知道是否可以将它向前推进,以便它从前台开始。我注意到当我使用 JOptionPane 时也会发生同样的事情。所有 JOptionPane 消息都出现在后台。仅当 GUI 从 virgo 服务启动时。如果我将 GUI 作为独立应用程序运行,我就没有这个问题。