我的JComboBox下拉列表中顯示酒店名稱列表中的問題。顯示ArrayList中的內容列表
我的ArrayList包含hotelNo,hotelName,city。
在我的GUI,我已經寫了這
Object[] hotelArr = { databaseconn.arrayListHere() };
@SuppressWarnings({ "rawtypes", "unchecked" })
// this just hide some unimportant warnings
JComboBox hotelList = new JComboBox(hotelArr);
hotelList.addActionListener(this);
frame.add(hotelList, BorderLayout.NORTH);
我可以點擊下拉列表中,但只顯示「[]」。我認爲他們被稱爲括號。 我希望它顯示hotelName的列表,這也存儲在ArrayList hotelInfo中,我已經放入一個名爲arrayListHere的方法。
那我該怎麼做呢?在這個問題上花了很多時間。無法在任何地方找到答案或幫助。我也檢查了文檔,但沒有得到任何我可以使用的東西。
,你可以做這行內容:System.out.println(databaseconn.arrayListHere());在開始的時候,告訴我們什麼是價值? – 2014-10-01 11:16:54
是的。我剛剛做了,結果是「[]」。 (1,SAS Radisson,Copenhagen,2,Grosvenor Hotel,Copenhagen] [1,Sas Radisson,Copenhagen,2, Grosvenor Hotel,Copenhagen,3,Hilton,London] [1,Sas Radisson,Copenhagen,2,哥本哈根格羅夫納酒店3,倫敦希爾頓酒店,4,Ritz,Oslo] [1,Sas Radisson,Copenhagen,格羅夫納酒店,哥本哈根3,希爾頓酒店,倫敦4,里茲,奧斯陸,5,Best Western,null] 「 – 2014-10-01 11:20:26
」[教程] /combobox.html)有關組合框的用法*如果您將其他對象放在組合框中,則默認渲染器會調用** toString **方法來提供一個字符串以顯示* – A4L 2014-10-01 11:20:38