如何從點擊的JOptionPane選項獲取輸入。 - java的
我怎樣才能得到被點擊了JOptionPane
從選項中輸入,而不是Okay
按鈕,但我已經提供了諸如Emerald
的選項,Autumn
等
這裏是我的代碼
public static ArrayList<String> Skins = new ArrayList<String>();
public static void skinJPanel() {
try {
String[] skins = {"Emerald", "Autumn", "Black Steel", "Blue Steel", "Creme Coffee", "Green Magic"};
for (int i = 0; i <= 5; i++) {
Skins.add(skins[i]);
}
JPanel panel = new JPanel();
panel.setSize(200, 200);
JList list = new JList(Skins.toArray());
JScrollPane scrollpane = new JScrollPane();
scrollpane = new JScrollPane(list);
panel.add(scrollpane);
scrollpane.getViewport().add(list);
String string = JOptionPane.showInputDialog(null, scrollpane, "Aftermath Skin Chooser", JOptionPane.PLAIN_MESSAGE);
System.out.println(string);
} catch (Exception e) {
e.printStackTrace();
}
Skins.clear();
}
所以,我假設你不想等待用戶點擊[好]/[取消],或者你只是想從'JList'中選擇的值? – MadProgrammer