JoptionPane多选和可滚动选项

时间:2014-12-09 13:05:39

标签: java swing joptionpane

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

问题是我需要结合两个功能,即滚动和多选选项。任何人都可以提供正确的代码。

2 个答案:

答案 0 :(得分:3)

  

我是JoptionPane的新手是否有任何方法可以让我多   选择和滚动功能。请在下面找到我的代码。

enter image description here

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