When creating a Yes/No JOptionPane, how do I default the value to No instead of Yes?

John Zukowski

You need to explicitly pass in the button labels and initial value via the showOptionDialog() method (or constructor).


int selection = JOptionPane.showOptionDialog(CreditDefaultLegPanel.this,
   "Are you sure you want to do something bad?,
   "Confirm Bad", JOptionPane.YES_NO_OPTION,
   JOptionPane.QUESTION_MESSAGE, null, 
   new String[] {"Yes", "No"}, "No");
if (selection == JOptionPane.YES_OPTION) {
  System.out.println("Yes...");
}
If you do this, you no longer get the automatic localization of Yes/No labels. You'll have to deal with that yourself/separately.
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact