JoptionPane 多选和可滚动选项

2023-12-09

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

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


我是 JoptionPane 的新手,有什么方法可以让我拥有多个 选择和滚动功能。请在下面找到我的代码。

  • 基于Oracle教程如何创建对话框 - 从对话框中获取用户的输入

  • Swing JComponents(其模型)被指定用于使用标准 Java 数据类型

  • 例如,有两个模型(对键盘上的数字0-9做出反应)

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();  
            }  
        });  
    }  
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

JoptionPane 多选和可滚动选项 的相关文章

随机推荐