| ... |
... |
@@ -57,7 +57,11 @@ import javax.swing.JComboBox; |
|
57
|
57
|
import javax.swing.JLabel;
|
|
58
|
58
|
import javax.swing.JPanel;
|
|
59
|
59
|
import javax.swing.SwingUtilities;
|
|
|
60
|
+import javax.swing.table.TableCellRenderer;
|
|
|
61
|
+import javax.swing.table.TableColumn;
|
|
|
62
|
+import javax.swing.table.TableColumnModel;
|
|
60
|
63
|
import java.awt.BorderLayout;
|
|
|
64
|
+import java.awt.Component;
|
|
61
|
65
|
import java.awt.event.ItemEvent;
|
|
62
|
66
|
import java.beans.PropertyChangeListener;
|
|
63
|
67
|
import java.io.File;
|
| ... |
... |
@@ -508,6 +512,9 @@ public class ReportModel extends AdminActionModel { |
|
508
|
512
|
if (reportColumnRenderersParameters != null) {
|
|
509
|
513
|
reportColumnRenderersParameters.consumeColumnRenderersSwing(resultTable);
|
|
510
|
514
|
}
|
|
|
515
|
+ resizeColumnWidth(resultTable,-1);
|
|
|
516
|
+
|
|
|
517
|
+
|
|
511
|
518
|
} catch (Exception e) {
|
|
512
|
519
|
clearResult(ui);
|
|
513
|
520
|
throw e;
|
| ... |
... |
@@ -516,6 +523,30 @@ public class ReportModel extends AdminActionModel { |
|
516
|
523
|
}
|
|
517
|
524
|
}
|
|
518
|
525
|
|
|
|
526
|
+ public static void resizeColumnWidth(JXTable table, int maxWidth) {
|
|
|
527
|
+ final TableColumnModel columnModel = table.getColumnModel();
|
|
|
528
|
+ for (int column = 0; column < table.getColumnCount(); column++) {
|
|
|
529
|
+ // Account for header size
|
|
|
530
|
+ TableColumn tableColumn = table.getColumnModel().getColumn(column);
|
|
|
531
|
+ TableCellRenderer renderer = tableColumn.getCellRenderer();
|
|
|
532
|
+ if (renderer==null) {
|
|
|
533
|
+ renderer = table.getTableHeader().getDefaultRenderer();
|
|
|
534
|
+ }
|
|
|
535
|
+ Component component = renderer.getTableCellRendererComponent(table, tableColumn.getHeaderValue(), false, false, -1, column);
|
|
|
536
|
+ double width = component.getPreferredSize().width;
|
|
|
537
|
+ for (int row = 0; row < table.getRowCount(); row++) {
|
|
|
538
|
+ renderer = table.getCellRenderer(row, column);
|
|
|
539
|
+ Component comp = table.prepareRenderer(renderer, row, column);
|
|
|
540
|
+ width = Math.max(comp.getPreferredSize().width + 1, width);
|
|
|
541
|
+ }
|
|
|
542
|
+ if (maxWidth>0 && width > maxWidth) {
|
|
|
543
|
+ width = maxWidth;
|
|
|
544
|
+ }
|
|
|
545
|
+ tableColumn.setPreferredWidth((int) width);
|
|
|
546
|
+ log.debug("Column {} - width (min/max/pref): {} {}/{}/{}", tableColumn.getModelIndex(), tableColumn.getWidth(), tableColumn.getMinWidth(), tableColumn.getMaxWidth(), tableColumn.getPreferredWidth());
|
|
|
547
|
+ }
|
|
|
548
|
+ }
|
|
|
549
|
+
|
|
519
|
550
|
private void clearResult(ReportUI ui) {
|
|
520
|
551
|
getResultModel().clear();
|
|
521
|
552
|
ui.getConfigurationPane().setTitle(null);
|