How do I change the Yes / No option in the confirmation dialog?

I want to change "YES" and "NO" to something like "Agree / Disagree." What should I do?

int reply = JOptionPane.showConfirmDialog(null, "Are you want to continue the process?", "YES?", JOptionPane.YES_NO_OPTION); 
+7
java swing jbutton joptionpane
source share
5 answers

You can do the following

 JFrame frame = new JFrame(); String[] options = new String[2]; options[0] = new String("Agree"); options[1] = new String("Disagree"); JOptionPane.showOptionDialog(frame.getContentPane(),"Message!","Title", 0,JOptionPane.INFORMATION_MESSAGE,null,options,null); 

as follows

enter image description here

See the showOptionDialog () function for more information.

+23
source share

You can use the options parameter to push custom parameters on showOptionDialog ;

 Object[] options = { "Agree", "Disagree" }; JOptionPane.showOptionDialog(null, "These are my terms", "Terms", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]); 
+4
source share

You might want to check out JOptionPane.showOptionDialog , which will allow you to enter a text parameter (in array form).

+3
source share

Try the following:

See JOptionPane Documentation

 JOptionPane(Object message, int messageType, int optionType, Icon icon, Object[] options, Object initialValue) 

where options specify buttons with initialValue. Therefore you can change them

Example

 Object[] options = { "Agree", "Disagree" }; JOptionPane.showOptionDialog(null, "Are you want to continue the process?", "information", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]); 
+3
source share

Try it!

 int res = JOptionPane.showConfirmDialog(null, "Are you want to continue the process?", "", JOptionPane.YES_NO_OPTION); switch (res) { case JOptionPane.YES_OPTION: JOptionPane.showMessageDialog(null, "Process Successfully"); break; case JOptionPane.NO_OPTION: JOptionPane.showMessageDialog(null, "Process is Canceled"); break; } 
+2
source share

All Articles