Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to add ActionListener to the button on JOptionPane?

Posted on 2002-06-12
5
Medium Priority
?
763 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 80 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

721 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