2013-08-17 16 views
7

Voglio cambiare SÌ e NO a qualcosa come Accetto/Non accetto. Cosa devo fare?Come modificare l'opzione Sì/No nella finestra di conferma?

int reply = JOptionPane.showConfirmDialog(null, 
              "Are you want to continue the process?", 
              "YES?", 
              JOptionPane.YES_NO_OPTION); 
+0

[come, ovviamente, tutto è Oracle Tutorial] (http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html#button) – mKorbel

risposta

3

Si potrebbe desiderare di checkout JOptionPane.showOptionDialog, che vi permetterà di spingere in un parametro di testo (in forma di array).

3

Provate questo:

Vedi JOptionPane documentation

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

dove le opzioni specifica i pulsanti con initialValue. Così si può cambiarle

Esempio

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

È possibile utilizzare il parametro options di spingere le opzioni personalizzate per showOptionDialog;

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

funziona e cambia per JOptionPane.showOptionDialog ma io vuoi cambiare per JOptionPane.showConfirmDialog È allo stesso modo o no? –

23

È possibile effettuare le seguenti

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

uscita è la seguente

enter image description here

Per maggiori dettagli sulla funzione showOptionDialog() vedi here.

+0

+1 immagine Alberino –

+0

per Sì, questo funziona come previsto, ma c'è un modo per cambiare il font di "Accetto" e pulsanti "disaccordo" ?. Voglio internazionalizzare la mia applicazione. – Sahan

2

Try This !!

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