2013-08-17 6 views

Antwort

3

Versuchen Sie diese:

Siehe JOptionPane documentation

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

wo Optionen die Tasten mit dem Anfangswert angibt. So können Sie sie ändern

Beispiel

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]); 
4

Sie den options Parameter verwenden können, um benutzerdefinierte Optionen zu showOptionDialog schieben;

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

Es funktioniert und für JOptionPane.showOptionDialog ändern, aber ich möchte für JOptionPane.showConfirmDialog ändern Ist es genauso oder nicht? –

23

können Sie folgendermaßen vorgehen

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); 

Ausgang ist als

enter image description here

here Weitere Details über die showOptionDialog() Funktion siehe folgt.

+0

+1 für das Post-Image –

+0

Ja, das funktioniert wie erwartet, aber gibt es eine Möglichkeit, die Schriftart der Schaltflächen "Agree" und "Disagree" zu ändern ?. Ich möchte meine Bewerbung internationalisieren. – Sahan

2

Versuchen Sie das !!

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; 
     }