Hi i want to show JOptionPane.showMessageDialog(null, "Appication already running");
for 10sec and then remove it.how can i dothat?
You can create a JOptionPane manually, without static methods:
JOptionPane pane = new JOptionPane("Your message", JOptionPane.INFORMATION_MESSAGE);
JDialog dialog = pane.createDialog(parent, "Title");
then you can show the dialog and fire up a timer to hide it after ten seconds.
I tried these answers and ran into the problem that showing the dialog is a blocking call, so a timer can't work. The following gets around this problem.
JOptionPane opt = new JOptionPane("Application already running", JOptionPane.WARNING_MESSAGE, JOptionPane.DEFAULT_OPTION, null, new Object[]{}); // no buttons
final JDialog dlg = opt.createDialog("Error");
new Thread(new Runnable()
{
public void run()
{
try
{
Thread.sleep(10000);
dlg.dispose();
}
catch ( Throwable th )
{
tracea("setValidComboIndex(): error :\n"
+ cThrowable.getStackTrace(th));
}
}
}).start();
dlg.setVisible(true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With