gpt4 book ai didi

java - 将数组的内容添加到 JFrame,添加 JPanel,添加 JScroll

转载 作者:行者123 更新时间:2023-11-30 06:28:19 31 4
gpt4 key购买 nike

String[] option = {"Adlawan", "Angeles", "Arreza", "Benenoso", "Bermas",
"Brebante", "Cabaylo", "C. Cainglet", "O. Cainglet",
"Calunsag", "Cameros", "Casanaan", "Catulong", "Chicote",
"Dela Paz", "Ea", "Echavez"};

int choose = JOptionPane.showOptionDialog(null, "WHICH EMPLOYEE'S DATA WOULD YOU
LIKE TO RESET?", "Click to Choose Type of Leave Credits",
JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE,
null, option, option[16]);

它运行完美,我遇到的唯一问题是 JOptionPane(带有可供选择的名称)不适合屏幕,我如何将名称添加到框架或面板中并放置将 JScroll 放入其中,使其适合屏幕。

最佳答案

您可以使用列表来显示选项,例如:

import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;

public class TestOptions {
public static void main(String[] args) {
String[] options = { "Adlawan", "Angeles", "Arreza", "Benenoso",
"Bermas", "Brebante", "Cabaylo", "C. Cainglet", "O. Cainglet",
"Calunsag", "Cameros", "Casanaan", "Catulong", "Chicote",
"Dela Paz", "Ea", "Echavez" };

JList list = new JList(options);
JScrollPane scrollPane = new JScrollPane(list);

int result = JOptionPane.showConfirmDialog(null, scrollPane,
"Select employee", JOptionPane.OK_CANCEL_OPTION);

if (result == JOptionPane.OK_OPTION) {
JOptionPane.showMessageDialog(null, list.getSelectedValue());
}
}
}

关于java - 将数组的内容添加到 JFrame,添加 JPanel,添加 JScroll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12701394/

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