void
packTable(final JTable table) Packs a table.
Resizes all columns to the maximum width of the values in each column.
for (int column = table.getColumnCount() - 1; column >= 0; column--) {
int maxWidth = 70;
for (int row = table.getRowCount() - 1; row >= 0; row--)
maxWidth = Math.max(maxWidth,
table.getRowMargin() + table
.getCellRenderer(row, column).getTableCellRendererComponent(table,
table.getValueAt(row, column), false, false, row, column)
.getPreferredSize().width);
...
void
packTables(final JTable tableOne, final JTable tableTwo) Packs two table and forces them to have the same column width.
packGenericTable(tableOne);
packGenericTable(tableTwo);
for (int i = 0; i < tableOne.getModel().getColumnCount(); i++) {
int tableWidth = tableOne.getColumnModel().getColumn(i).getPreferredWidth();
int footerTableWidth = tableTwo.getColumnModel().getColumn(i).getPreferredWidth();
if (tableWidth > footerTableWidth) {
tableTwo.getColumnModel().getColumn(i).setPreferredWidth(tableWidth);
} else {
...