Here you can find the source of optionDialog(String title, String text, String option1, String option2, int defaultOption, JFrame parentFrame)
public static int optionDialog(String title, String text, String option1, String option2, int defaultOption, JFrame parentFrame)
//package com.java2s; //License from project: Open Source License import javax.swing.JFrame; import javax.swing.JOptionPane; public class Main { public static int optionDialog(String title, String text, String option1, String option2, int defaultOption, JFrame parentFrame) { if (defaultOption < 1) defaultOption = 1;//from w w w .j a va2 s . c om if (defaultOption > 2) defaultOption = 2; Object[] options = { option1, option2 }; int n = JOptionPane.showOptionDialog(parentFrame, text, title, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[defaultOption - 1]); n = n + 1; return n; } }