2012-03-01 66 views

回答

10

您可以使用showMessageDialog(),創建JComboBox並轉換爲可編輯setEditable()

例子:

String[] list = {"A", "B", "C"}; 
JComboBox jcb = new JComboBox(list); 
jcb.setEditable(true); 
JOptionPane.showMessageDialog(null, jcb, "select or type a value", JOptionPane.QUESTION_MESSAGE); 

您可以檢索在JComboBox與價值:

jcb.getSelectedItem() 
+0

我怎麼了編輯ComboBox裏面的類型值? – KJW 2012-03-01 21:13:05

+0

也使用'getSelectedItem()'。它沒有工作? – 2012-03-01 21:19:57

+0

如果我想把數字放入'list = {1,2,3,4}'這會起作用嗎? – 2017-03-08 09:36:24