File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Question about JOptionPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Question about JOptionPane" Watch "Question about JOptionPane" New topic
Author

Question about JOptionPane

arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
Hello Everybody,
I was trying to explore JOptionPane class and got two questions:-
1. How to set the icon for this?
2. How to trap the action for "YES" "NO" or "Cancel" button for same? as I am not able to find any action listener.
regards,
Arun
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Arun,

1. How to set the icon for this?
2. How to trap the action for "YES" "NO" or "Cancel" button for same? as I am not able to find any action listener.

1. There are various static methods in the JOptionPane class that accept an Icon as a parameter for example:

There are also a constructors which accept an Icon:

2. The static methods generally return int, String or Object. If you don't use the static methods then you'll have to make a call to getValue() which returns an Object.
A good idea would be to look at the javadocs on JOptionPane. It contains a lot of methods and properties, but isn't as complex as it first looks.
Hope this helps
Michael Morris
SCJP2


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
Thanks Michael. It works easily.
arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
Sorry to ask it again. But another experipent on this JOptionPane. How to set the Top left Icon of the (Message)Box. I tried with following code but in vain. But if i try putting the test part also into the constructorit works very well. But than the problem would be that it pop the message window by default you can't call it as per your requirement.
I know that setIconImage is avaiable for Frames only. But is there any workaround as this is giving trouble to my client?
regards,
Arun

Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Arun,
There are several ways you could go about doing this but the most straight forward would be something like this:

That should set the Icon on your JOptionPane. I didn't test this out so let me know if it works.
Hope this helps
Michael Morris
SCJP2
[ March 25, 2002: Message edited by: Michael Morris ]
 
wood burning stoves
 
subject: Question about JOptionPane
 
Similar Threads
JOptionPane
java alert
JOptionPane Question!
How to make JDialog has default microsoft window color and style
How to bring user back to the internalframe after JOptionPane?