File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JOptionPane.showConfirmDialog -- i need help! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JOptionPane.showConfirmDialog -- i need help!" Watch "JOptionPane.showConfirmDialog -- i need help!" New topic

JOptionPane.showConfirmDialog -- i need help!

Em Aiy
Ranch Hand

Joined: May 11, 2006
Posts: 226

i am displaying a confirm dialog box like

it displays a dialog box, with "YES" option selected. What i want is to make the default selection of "NO" option. How can i?

The difference between <b>failure</b> and <b>success</b> is often being <b>right</b> and being <b>exactly right</b>.
dinesh Venkatesan
Ranch Hand

Joined: Oct 12, 2006
Posts: 134
mport javax.swing.*;

public class Tester {
public static void main(String[] args) {
JButton yesButton = new JButton("Yes");
JButton noButton = new JButton("No");
Object buttonArray[] = {yesButton,noButton};
JOptionPane.showOptionDialog(null,"Hai","Hai",JOptionPane.YES_NO_OPTION,JOptionPane.PLAIN_MESSAGE,new ImageIcon("test.jpg"),buttonArray,buttonArray[1]);

Hope this helps for you!
Marc Peabody
pie sneak

Joined: Feb 05, 2003
Posts: 4727

"Muhammad Ali", we don't have too many rules around here but we do have a Naming Policy. Please adjust your display name accordingly.

A good workman is known by his tools.
I agree. Here's the link:
subject: JOptionPane.showConfirmDialog -- i need help!
It's not a secret anymore!