Java Utililty Methods JTable Pack

List of utility methods to do JTable Pack

  1. HOME
  2. Java
  3. J
  4. JTable Pack

Description

The list of methods to do JTable Pack are organized into topic(s).

Method

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 {
...

AltStyle によって変換されたページ (->オリジナル) /