JoptionPane多选和可滚动选项 [英] JoptionPane multi select and srollable option

查看:106
本文介绍了JoptionPane多选和可滚动选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm new to JoptionPane is there any method that i can have multi select and scrollable feature. Please find my code below.

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

问题是我需要结合滚动和多选选项这两个功能,任何人都可以为我提供适当的代码

problem is i need to combine both features i.e., both scrolling and multi select options.Can any one provide me a proper code.

推荐答案

我是JoptionPane的新手,我可以使用多种方法吗? 选择和滚动功能.请在下面找到我的代码.

I'm new to JoptionPane is there any method that i can have multi select and scrollable feature. Please find my code below.

  • 基于Oracle教程如何制作对话框-通过对话框获取用户的输入

    Swing JComponents(其模型)被指定为与标准Java数据类型一起使用

    Swing JComponents (its models) are designated to works with standard Java data types

    例如,有两种型号(通过键盘对数字0-9进行反应)

    for example, there are two models (react to numbers 0-9 from keyboard)

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

    这篇关于JoptionPane多选和可滚动选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆