gpt4 book ai didi

java - JoptionPane 多选和可滚动选项

转载 作者:行者123 更新时间:2023-11-29 05:13:40 25 4
gpt4 key购买 nike

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

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

最佳答案

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

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

关于java - JoptionPane 多选和可滚动选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27379663/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com