2011-08-15 54 views
0

我有這樣散列表的JTable?

HashTable<String, String> table=new HashTable<String, String>(); 
table.put("1","ABC"); 
.......continues 
與枚舉我能得到這個鍵和值兩個字符串

現在哈希表說str1和STR2。

我想JTable中添加這兩個字符串值。每當一個新的價值將遍歷並JTable中添加。這個怎麼做 ?

記住我別無選擇,使用HashMap中。

回答

4

您可以使用此:

DefaultTableModel dtm = new DefaultTableModel(); 
JTable table = new JTable(dtm); 
for(Entry<?, ?> entry: yourHashTable.entrySet()) { 
    dtm.addRow(new Object[] {entry.getKey(), entry.getValue()}); 
}