开发者

HashTable to JTable?

开发者 https://www.devze.com 2023-03-28 07:01 出处:网络
I have a HashTable like HashTable<String, String> table=new HashTable<String, String&开发者_StackOverflow中文版gt;();

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

精彩评论

暂无评论...
验证码 换一张
取 消