problem in showMessageDialog method of JOptionPane

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

publicclass SwingCompextends JFrameimplements ActionListener{

public SwingComp()

{

JPanel p =new JPanel();

JButton b =new JButton("OK");

b.addActionListener(this);

p.add(b);

add(p);

pack();

setVisible(true);

}

publicstaticvoid main(String args[])

{

new SwingComp();

}

publicvoid actionPerformed(ActionEvent e)

{

{

JOptionPane.showMessageDialog( null,"Message","Title", JOptionPane.ERROR_MESSAGE );

}

//JDialog d = new JDialog();

//JButton b1 = new JButton("some");

//d.add(b1);

//d.pack();

//d.setVisible(true);

}

}

After running the above code is there any way in which I can add action listener to theok button that is displayed byJOptionPane.showMessageDialog( null, "Message", "Title", JOptionPane.ERROR_MESSAGE );dialog.

[2113 byte] By [jaaya] at [2007-10-2 20:54:03]
# 1
you probably don't want one. the call to showMessageDialog will block (i.e. it won't return) until after the user has pressed the ok button.
Ken_Sa at 2007-7-13 23:38:29 > top of Java-index,Java Essentials,New To Java...
# 2

I know that . I am asking this question because in the application that I am working on, this error dialog is invoked from a button in another dialog.

The problem that I am facing is , if i click ok button of JOptionPane then

the dialog that is behind this one also gets closed.

That is why I needed to add actionListener to the button so that i create a situation in which the dialog that invoked this error dialog doesnt get closed.

Regards

jaaya at 2007-7-13 23:38:29 > top of Java-index,Java Essentials,New To Java...
# 3

You'll need to customize the option pane in order to achieve what you want. The following link demonstrates customizing a JOptionPane dialog. You'll need to adapt the code for your purposes but it clearly demonstrates the technique.

http://forum.java.sun.com/thread.jspa?forumID=513&threadID=248471

paternostroa at 2007-7-13 23:38:29 > top of Java-index,Java Essentials,New To Java...
# 4

> You'll need to customize the option pane in order to

> achieve what you want. The following link

> demonstrates customizing a JOptionPane dialog.

> You'll need to adapt the code for your purposes but

> it clearly demonstrates the technique.

>

> http://forum.java.sun.com/thread.jspa?forumID=513&thre

> adID=248471

Thanks for the information. Is there any other way by which the problem can be solved, I mean without customising...

jaaya at 2007-7-13 23:38:29 > top of Java-index,Java Essentials,New To Java...
# 5

No, because for you to add a listener to the JOptionPane's button you'll need to retrieve a reference to the option pane in order to use the technique of traversing the pane's components. Since the showMessageDialog() method is static there's no way to retrieve the needed reference.

paternostroa at 2007-7-13 23:38:29 > top of Java-index,Java Essentials,New To Java...