unable to close OK button of JOption dialog when 2 dialogs are displayed.
1. Run the below sample program
2. Click the "Click me" button immediately.
3. two dialogs are displayed, one by mouse click and another by threa.d
4. Now OK button of both dialogs are not working.
Expected behaviour:
the ok button of second dialog shold be active and should close the dialog.
Sample:
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
publicclass test
{
publicstaticvoid main(String arg[])
{
MainFrame frm1 =new MainFrame();
frm1.setVisible(true);
}
}
class MainFrameextends JFrameimplements Runnable, ActionListener
{
messagedlg errdlg =new messagedlg();
JButton btn;
MainFrame()
{
btn =new JButton("Click Me");
JPanel pnl =new JPanel();
this.getContentPane().add(pnl);
pnl.setLayout(new FlowLayout());
pnl.add(btn);
btn.addActionListener(this);
setSize(400,400);
setLocation(400,200);
Thread t =new Thread(this);
t.start();
}
publicvoid run()
{
errdlg.showError(this,"mainscreen message");
}
publicvoid actionPerformed(ActionEvent ae)
{
System.out.println("action start");
//SwingUtilities.invokeLater(Thread.currentThread());
errdlg.showError(this,"mainscreen action message");
System.out.println("action end");
}
}
class messagedlg
{
publicstaticvoid showError(JFrame frame, String msg)
{
try{Thread.sleep(1000);}catch(Exception ex){}
Object[] options ={"OK"};
int n = JOptionPane.showOptionDialog(frame,(Object)msg, msg,
JOptionPane.OK_OPTION,1,
null,//don't use a custom Icon
options,//the titles of buttons
options[0]);//default button title
}
}

