+ // resize the column widths to content size
+ for (int i = 0; i < tableReport.getColumnCount(); i ++) {
+
+ TableColumn clm = tableReport.getColumnModel().getColumn (i);
+ int preferredWidth = clm.getMinWidth()+10;
+ int maxWidth = 300;
+ int minWidth = 100;
+ for (int r = 0; r < tableReport.getRowCount(); r ++) {
+ TableCellRenderer rend = tableReport.getCellRenderer(r, i);
+ Component c = tableReport.prepareRenderer(rend, r, i);
+ int width = c.getPreferredSize().width + tableReport.getIntercellSpacing().width;
+ preferredWidth = Math.max (preferredWidth, width+10);
+ if (preferredWidth >= maxWidth)
+ {
+ preferredWidth = maxWidth;
+ break;
+ }
+ }
+ clm.setPreferredWidth(Math.max(minWidth, preferredWidth));
+ }