If I'm reading this right, something like...
Object[][] data = new Object[c.size()][2];
int row = 0;
for (Object key : c.keySet()) {
data[row][0] = key;
Employee emp = (Employee)c.get(key);
data[row][1] = ...; // Get name from Employee object...
// Personally, I prefer to assign the Employee object to
// the column of the row and use a TableCellRenderer to
// renderer it
}
String[] headers = {"Employee Code", "Employee First Name"};
JTable table = new JTable(data, headers);
Should work...
Now, if you want a stronger relationship between the HashMap
and TableModel
(so you could add content to the table and it would update the HashMap
), you're going to need to use an AbstractTableModel
and get your hands dirty mapping the content between the requirements of the model and the HashMap