X-Git-Url: https://harishankar.org/repos/?p=habeas.git;a=blobdiff_plain;f=src%2Fhabeas%2FNoticesReportViewDialog.java;fp=src%2Fhabeas%2FNoticesReportViewDialog.java;h=8852409f511531cdc2cbfcbd7a90b46d40d49a84;hp=2636cbc51f4938a2ad0c2655a2663b1f74ac6a6f;hb=2d04b06ea9a39c05dd3db560f3fc573696c7e36e;hpb=bc2309fb0a6c83daa94320d06619c1f8b153696c diff --git a/src/habeas/NoticesReportViewDialog.java b/src/habeas/NoticesReportViewDialog.java index 2636cbc..8852409 100644 --- a/src/habeas/NoticesReportViewDialog.java +++ b/src/habeas/NoticesReportViewDialog.java @@ -5,12 +5,17 @@ */ package habeas; +import java.awt.Component; import java.util.ArrayList; import javax.swing.JFileChooser; import javax.swing.JOptionPane; +import javax.swing.JTable; import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableColumn; +import javax.swing.table.TableColumnModel; /** * @@ -77,7 +82,9 @@ public class NoticesReportViewDialog extends javax.swing.JDialog { } )); + tableReport.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF); tableReport.setCellSelectionEnabled(true); + tableReport.setComponentPopupMenu(popMenu); jScrollPane2.setViewportView(tableReport); checkFilterByClient.setText("Filter by Client"); @@ -103,9 +110,9 @@ public class NoticesReportViewDialog extends javax.swing.JDialog { .addContainerGap() .addComponent(checkFilterByClient, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(comboClients, javax.swing.GroupLayout.PREFERRED_SIZE, 322, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(comboClients, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonApply, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(buttonApply, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -228,7 +235,6 @@ public class NoticesReportViewDialog extends javax.swing.JDialog { } }; tableReport.setModel(mdl); - tableReport.setComponentPopupMenu(popMenu); labelReportTitle.setText(title); populateReport (); @@ -242,8 +248,27 @@ public class NoticesReportViewDialog extends javax.swing.JDialog { for (int j = 0; j < reportCols.length; j ++) row[j] = reportData.get(i+j); mdl.addRow (row); - } + // 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)); + } } private void populateClients() {