HashTable to JTable?
I have a HashTable like
HashTable<String, String> table=new HashTable<String, String&开发者_StackOverflow中文版gt;();
table.put("1","ABC");
.......continues
Now with enumeration I can get this key and values in two strings say str1 and str2.
I want to add this two string values in a JTable. Every time a new value will iterate and will add in the JTable. How to do this ?
Remember I have no option to use a HashMap.
You can use this:
DefaultTableModel dtm = new DefaultTableModel();
JTable table = new JTable(dtm);
for(Entry<?, ?> entry: yourHashTable.entrySet()) {
dtm.addRow(new Object[] {entry.getKey(), entry.getValue()});
}
精彩评论