gpt4 book ai didi

java - 第二个 JOptionPane 位于所有程序后面

转载 作者:行者123 更新时间:2023-12-02 04:20:51 25 4
gpt4 key购买 nike

在我的 Java 代理中,如果我依次放置两个 JOptionPane,则第二个将位于我打开的所有应用程序后面。

我已经尝试过了

  • null 更改为 this; 但我明白了:

    The method showMessageDialog(Component, Object, String, int) in the type JOptionPane is not applicable for the arguments (JavaAgent, String, String, int)"
  • 获取所有可能的父组件。 但也没有成功
  • 在我的 java.policy 文件中设置 setAlwaysOnTop 权限,也不起作用
  • 我的类已经扩展了我需要的另一个类,因此我无法扩展 javax.swing.JDialog

我使用的代码是:

public class JavaAgent extends AgentBase{

private static int erros=0;
private static int count=0;

public int getErros(){return erros;}
public int getCount(){return count;}

public void NotesMain() {
System.out.println("\n\nStart of Agente!");

try {

Session session = getSession();

Database db = session.getCurrentDatabase();
View vw = db.getView("vwTodas");

JFileChooser fc = new JFileChooser();
//Get the file by file chooser

/* Filter FileReader through a Buffered read to read a line at a
time */
BufferedReader bufRead = null;

try{
//read the file
//work in the file
}

}catch(IOException a){
JOptionPane.showMessageDialog(null,"Problems reading the file!","Problems!",JOptionPane.INFORMATION_MESSAGE);
}finally{
try{
bufRead.close();
}catch(IOException b){
JOptionPane.showMessageDialog(null, "Problems closing the file!", "Problems!", JOptionPane.INFORMATION_MESSAGE);
}
}

System.out.println("\n\nEnd of Agente!");

JOptionPane.showMessageDialog(frame,"Documents sent: " + count + "\nErrors during the import: " + erros + "\nTotal: " + (count+erros),"Erro",JOptionPane.ERROR_MESSAGE);
}

} catch(NotesException e) {
e.printStackTrace();
}

}

}

有什么想法吗?

最佳答案

您可以创建一个 JFrame,将其设置为始终位于顶部,并将该 JFrame 作为 JOptionPane 的父组件传递:

JFrame parentFrame = new JFrame();
parentFrame.setAlwaysOnTop(true);
JOptionPane.showMessageDialog(null, "Problems closing the file!", "Problem!", JOptionPane.INFORMATION_MESSAGE);

或者,如果您已有可用的父组件,那么您应该将其用作 JOptionPane 的父组件

关于java - 第二个 JOptionPane 位于所有程序后面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32788775/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com