2013-08-17 48 views
7

我想将YES和NO更改为Like/Disagree。 我该怎么办?如何在确认对话框中更改是/否选项?

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

[如明明一切都是甲骨文教程](http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html#button) – mKorbel

回答

3

试试这个:

JOptionPane documentation

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

其中options指定与初值的按钮。所以,你可以改变它们

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

可以使用options参数推定制选项showOptionDialog;

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

它工作和更改JOptionPane.showOptionDialog但我想改变为JOptionPane.showConfirmDialog 这是不是也一样? –

23

你可以做以下

​​

输出如下

enter image description here

有关showOptionDialog()函数的更多详细信息,请参阅here

+0

对帖子图片+1 +1 –

+0

是的,这是按预期工作,但有没有办法改变“同意”和“不同意”按钮的字体?我想将我的应用程序国际化。 – Sahan

2

试试这个!

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; 
     } 
相关问题