String[] options = {"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 One Choose ", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null,
option, option[16]);
if(choose == 0)
{
JOptionPane.showMessageDialog(null, Ms. Adlawan is tall);
}
else if (choose == 1)
{
JOptionPane.showMessageDialog(null, Mr. Angeles is old);
}
这些是我上面的代码。它运行完美,如果我运行这些代码,将出现17个按钮,如果我单击“Adlawan”代表(选择== 0)消息(Adlawan夫人很高)出现,如果我点击“安吉利斯”代表(选择== 1)出现消息(安吉利斯先生老了)。我的问题是所有17选项都不适合屏幕,我怎么能让这17个选项按钮适合屏幕。我已经尝试过JPanel并将JScrollPane添加到面板并将这些选项按钮添加到面板但它不起作用。任何帮助将非常感谢。感谢。
答案 0 :(得分:0)
我建议您使用JOptionPane.showInputDialog
。
String selected = (String)JOptionPane.showInputDialog(
null,
"WHICH EMPLOYEE'S DATA WOULD YOU LIKE TO RESET?",
"Select One To Choose",
JOptionPane.DEFAULT_OPTION,
null, //icon
options ,
options[0]);
if(selected!=null){
System.out.println("Selected option : " + selected);
}