How to add ActionListener to the button on JOptionPane?

 I want to add my ActionListener to the buttons on the JOptionPane. And I don't want the message box disappear after I press any buttons if my validation checking return false. Thank you.
JavaSlaveAsked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
Have a look at the javadoc.

To create and use an JOptionPane directly, the standard pattern is roughly as follows:
     JOptionPane pane = new JOptionPane(arguments);
     pane.set.Xxxx(...); // Configure
     JDialog dialog = pane.createDialog(parentComponent, title);
     dialog.show();


Here's the javadoc for one of the ctor's mentioning that you can pass buttons in the options array:

public JOptionPane(Object message,
                   int messageType,
                   int optionType,
                   Icon icon,
                   Object[] options)Creates an instance of JOptionPane to display a message with the specified message type, icon, and options. None of the options is initially selected.
The options objects should contain either instances of Components, (which are added directly) or Strings (which are wrapped in a JButton). If you provide Components, you must ensure that when the Component is clicked it messages setValue in the created JOptionPane.


0
 
objectsCommented:
Don't use the convience method, and instead construct the JOptionPane contents yourself.
0
 
JavaSlaveAuthor Commented:
Hi Objects,
  Can you tell me more about that ? Bcos of I've no idea how to do it..

Thank you .
0
 
girionisCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this
question is:

- points to objects

Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

girionis
Cleanup Volunteer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.