SwingUtilities.getWindowAncestor(コンポーネント)は、コンポーネントの最初の祖先ウィンドウを返すメソッドです。
JLabelと組み合わせて(コンポーネントとして)これを使用して、JOptionPaneメッセージダイアログウィンドウへの参照を取得し、10秒に設定されたタイマーメソッド内で閉じることができます。そのような何か:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
public class TestClass {
public static void main(String[] args)
{
errorpopup(new Exception("Error"));
}
private static void errorpopup(Exception m)
{
JLabel messageLabel = new JLabel("<html><body><p style='width: 300px;'>"+m.toString()+"</p></body></html>");
Timer timer = new Timer(10000,
new ActionListener()
{
@Override
public void actionPerformed(ActionEvent event)
{
SwingUtilities.getWindowAncestor(messageLabel).dispose();
}
});
timer.setRepeats(false);
timer.start();
JOptionPane.showMessageDialog(null, messageLabel, "Error Window Title", JOptionPane.ERROR_MESSAGE);
}
}
また、このリンクは、それを行うことができる方法の別の例があります:あなたはそれがあなたの目的に合うようにするために仕事の少しを行う必要があります How to close message dialog programmatically?
が、それは示していどのようにあなたはきちんとしているユーザーにカウントダウンを表示することができます。
ここをクリックしてください:https://docs.oracle.com/javase/tutorial/uiswing/misc/timer.html – user1803551