我是JoptionPane的新手是否有任何方法可以使用多选和可滚动功能。请在下面找到我的代码。
String bigList[] = new String[100];
for (int i = 0; i < bigList.length; i++) {
bigList[i] = Integer.toString(i);
}
滚动我正在使用
JOptionPane.showInputDialog(new JFrame(), "Pick a printer", "Input", JOptionPane.QUESTION_MESSAGE,null, bigList, "Titan");
用于多选我使用
JList list = new JList(bigList);
JOptionPane.showMessageDialog(null, list, "Select Test Case (For Multiple Selections Press 'Ctrl') ", JOptionPane.PLAIN_MESSAGE);
问题是我需要结合两个功能,即滚动和多选选项。任何人都可以提供正确的代码。
答案 0 :(得分:3)
我是JoptionPane的新手是否有任何方法可以让我多 选择和滚动功能。请在下面找到我的代码。
基于Oracle教程How to Make Dialogs - Getting the User's Input from a Dialog
Swing JComponents(其模型)被指定用于标准Java数据类型
例如,有两个模型(对键盘中的数字0-9作出反应)
import java.awt.EventQueue;
import javax.swing.Icon;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
public class MyOptionPane {
public MyOptionPane() {
Icon errorIcon = UIManager.getIcon("OptionPane.errorIcon");
Object[] possibilities = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
Integer i = (Integer) JOptionPane.showOptionDialog(null,
null, "ShowInputDialog",
JOptionPane.PLAIN_MESSAGE, 1, errorIcon, possibilities, 0);
// or
Integer ii = (Integer) JOptionPane.showInputDialog(null,
"Select number:\n\from JComboBox", "ShowInputDialog",
JOptionPane.PLAIN_MESSAGE, errorIcon, possibilities, "Numbers");
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
MyOptionPane mOP = new MyOptionPane();
}
});
}
}
答案 1 :(得分:0)
得到了答案
JList list = new JList(bigList);
JScrollPane jscrollpane=new JScrollPane();
jscrollpane.setViewportView(list);
JOptionPane.showMessageDialog(null, jscrollpane, "Select Value", JOptionPane.PLAIN_MESSAGE);