This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JOptionPane.showConfirmDialog -- i need help!" Watch "JOptionPane.showConfirmDialog -- i need help!" New topic
Author

JOptionPane.showConfirmDialog -- i need help!

Em Aiy
Ranch Hand

Joined: May 11, 2006
Posts: 226
hi,

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!
dinesh.
Marc Peabody
pie sneak
Sheriff

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JOptionPane.showConfirmDialog -- i need help!
 
Similar Threads
JComboBox event order.
JOptionPane confirmation dialog box functionality issue
Modal Dialog without java coffee cup icon.
making "Exit" option in JMenu
Generic Ok / Cancel Screen --- Alert doesn't do