Solved

How to add ActionListener to the button on JOptionPane?

Posted on 2002-06-12
5
701 Views
Last Modified: 2010-03-31
 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.
0
Comment
Question by:JavaSlave
  • 2
5 Comments
 
LVL 92

Expert Comment

by:objects
ID: 7074898
Don't use the convience method, and instead construct the JOptionPane contents yourself.
0
 

Author Comment

by:JavaSlave
ID: 7079955
Hi Objects,
  Can you tell me more about that ? Bcos of I've no idea how to do it..

Thank you .
0
 
LVL 92

Accepted Solution

by:
objects earned 20 total points
ID: 7079963
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
 
LVL 35

Expert Comment

by:girionis
ID: 8860379
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

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now