2
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(带有要选择的名称)不适合屏幕,我如何将名称添加到框架或面板中并将 aJScroll放入其中以使其适合屏幕。

4

1 回答 1

5

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

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());
        }
    }
}
于 2012-10-03T03:52:16.063 回答