Reuben
Reuben

Reputation: 5736

HashTable to JTable?

I have a HashTable like

HashTable<String, String> table=new HashTable<String, String>();
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.

Upvotes: 0

Views: 1234

Answers (1)

aymeric
aymeric

Reputation: 3895

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()});
}

Upvotes: 4

Related Questions