2013-08-17 31 views
7

Tôi muốn thay đổi CÓ và KHÔNG thành một cái gì đó như Đồng ý/Không đồng ý. Tôi nên làm gì?Làm cách nào để thay đổi tùy chọn Có/Không trong hộp thoại xác nhận?

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

[như rõ ràng là tất cả mọi thứ là Oracle hướng dẫn] (http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html#button) – mKorbel

Trả lời

3

Bạn có thể muốn thanh toán JOptionPane.showOptionDialog, điều này sẽ cho phép bạn đẩy tham số văn bản (dưới dạng mảng).

3

Hãy thử điều này một:

Xem JOptionPane documentation

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

nơi tùy chọn xác định các nút với initialValue. Vì vậy, bạn có thể thay đổi chúng

Ví dụ

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

Bạn có thể sử dụng tham số options để đẩy tùy chọn tùy chỉnh để showOptionDialog;

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

Nó làm việc và thay đổi cho JOptionPane.showOptionDialog nhưng tôi muốn thay đổi cho JOptionPane.showConfirmDialog Có giống như vậy hay không? –

23

Bạn có thể làm như sau sản lượng

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

như sau

enter image description here

Để biết thêm chi tiết về showOptionDialog() chức năng thấy here.

+0

+1 cho hình ảnh bài đăng –

+0

Có điều này đang hoạt động như mong đợi, nhưng có cách nào để thay đổi phông chữ của nút "Đồng ý" và "Không đồng ý" không ?. Tôi muốn quốc tế hóa đơn đăng ký của mình. – Sahan

2

Hãy thử tính năng này !!

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; 
     } 
Các vấn đề liên quan