显示一个错误对话框,显示消息’alert’:
JOptionPane.showMessageDialog(null, "alert", "alert", JOptionPane.ERROR_MESSAGE);
显示内部信息对话框,其中包含“信息”消息:
JOptionPane.showInternalMessageDialog(frame, "information",
"information", JOptionPane.INFORMATION_MESSAGE);
注意这是一个内部的框,你无法拖出去父布局
显示选项 是/否和消息’选择一个的信息面板:
JOptionPane.showConfirmDialog(null,
"choose one", "choose one", JOptionPane.YES_NO_OPTION);
这个方法可以返回int,如果点击是,返回0,点击否,则返回1,以此界定用户的选择
显示内部信息对话框,其中包含选项是/否/取消,并显示“请选择一个”和标题信息:
JOptionPane.showInternalConfirmDialog(frame,
"please choose one", "information",
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);
这也是一个只能在panel或者jframe中拖动的对话框
显示一个警告对话框,其中包含选项OK,CANCEL,标题’Warning’和消息’单击OK继续’:
Object[] options = { "OK", "CANCEL" };
JOptionPane.showOptionDialog(null, "Click OK to continue", "Warning",
JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE,
null, options, options[0]);
显示一个对话框,要求用户输入一个字符串:
String inputValue = JOptionPane.showInputDialog("Please input a value");
显示一个对话框,要求用户选择一个字符串:
Object[] possibleValues = { "First", "Second", "Third" };
Object selectedValue = JOptionPane.showInputDialog(null,
"Choose one", "Input",
JOptionPane.INFORMATION_MESSAGE, null,
possibleValues, possibleValues[0]);
参考
JDK1.6 中文文档