I have several JTables with several columns each. Each table is displayed on a different tab in a JTabbed Pane. These columns have the same header name among the tables, but different values in the columns. I am trying to allow the comparison of a header among all of the tables by right clicking a header, and hitting compare. This opens a new JDialog while passing a List of columns with the matching header that was chosen:
public void actionPerformed(ActionEvent arg0) {
List<TableColumn> columns = new ArrayList<TableColumn>();
for (int i = 0; i < tables.size(); i++) {
String tableName = tabPane.getTitleAt(i);
JTable tempTable = (JTable) tables.get(tableName);
// Get column at the channel name used
TableColumn col = tempTable.getColumn("chosen header");
// Add the column to the list of channel columns
columns.add(col);
}
new comparisonDialog(UI.getFrame(), "chosen header",
columns);
}
This appears to work correctly, storing all of the common columns for the tables into a list that is passed to a new JDialog. It also seems to work when I display a table with these columns in the new JDialog:
JTable table = new JTable();
for (TableColumn col : passedColumnList) {
col.setHeaderValue(col.getHeaderValue());
table.addColumn(col);
}
The correct columns are displayed, however:
- All of the data in the column is missing
- The columns seem to be linked to the tables they came from, as resizing one resizes the column in the table it came from!
Am I missing something simple here?