Revision: 1283
Author:   mathiasbr
Date:     2006-08-08 06:55:54 -0700 (Tue, 08 Aug 2006)
ViewCVS:  http://svn.sourceforge.net/spring-rich-c/?rev=1283&view=rev

Log Message:
-----------
All rows where evaluated to determine columns widths.

Modified Paths:
--------------
    
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/table/TableUtils.java
Modified: 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/table/TableUtils.java
===================================================================
--- 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/table/TableUtils.java
  2006-08-08 07:17:58 UTC (rev 1282)
+++ 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/table/TableUtils.java
  2006-08-08 13:55:54 UTC (rev 1283)
@@ -19,7 +19,11 @@
 import java.awt.Dimension;
 import java.awt.Point;
 import java.awt.Rectangle;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
+import java.util.ArrayList;
 import java.util.Date;
+import java.util.List;
 
 import javax.swing.JLabel;
 import javax.swing.JTable;
@@ -43,7 +47,8 @@
  * @author Keith Donald
  */
 public class TableUtils {
-       public static void scrollToRow(JTable table, int row) {
+
+    public static void scrollToRow(JTable table, int row) {
                if (!(table.getParent() instanceof JViewport)) {
                        return;
                }
@@ -122,26 +127,34 @@
                return getUnfilteredTableModel(table.getModel());
        }
 
-       public static void sizeColumnsToFitRowData(JTable table) {
+    public static void sizeColumnsToFitRowData(JTable table) {
+        sizeColumnsToFitRowData(table, false);
+    }
+
+    public static void sizeColumnsToFitRowData(JTable table, boolean 
onlyFirstRow) {
                if (table.getRowCount() > 0) {
-                       for (int col = 0; col < table.getColumnCount(); col++) {
-                               TableColumn column = 
table.getColumnModel().getColumn(col);
-                               TableCellRenderer r = 
table.getColumnModel().getColumn(col).getCellRenderer();
-                               if (r == null) {
-                                       Object val = table.getValueAt(0, col);
-                                       if (val != null) {
-                                               r = 
table.getDefaultRenderer(val.getClass());
-                                       }
-                               }
-                               if (r != null) {
-                                       Component c = r
-                                                       
.getTableCellRendererComponent(table, table.getValueAt(0, col), false, false, 
0, col);
-                                       int cWidth = column.getPreferredWidth();
-                                       if (c.getPreferredSize().width > 
cWidth) {
-                                               
column.setPreferredWidth(c.getPreferredSize().width + UIConstants.ONE_SPACE);
-                                               
column.setWidth(column.getPreferredWidth());
-                                       }
-                               }
+                       for (int col = 0, colSize = table.getColumnCount(); col 
< colSize; col++) {
+                int width = 0;
+                TableColumn column = table.getColumnModel().getColumn(col);
+                TableCellRenderer r = 
table.getColumnModel().getColumn(col).getCellRenderer();
+                for (int row = 0, rowSize = onlyFirstRow ? 1 : 
table.getRowCount(); row < rowSize; row++) {
+                    Object val = table.getValueAt(row, col);
+                               if (r == null) {
+                                       if (val != null) {
+                                               r = 
table.getDefaultRenderer(val.getClass());
+                                       }
+                               }
+                               if (r != null) {
+                                       Component c = r
+                                .getTableCellRendererComponent(table, val, 
false, false, row, col);
+                                       int cWidth = c.getPreferredSize().width;
+                        if(cWidth > width) {
+                            width = cWidth;
+                        }
+                               }
+                       }
+                column.setPreferredWidth(width + UIConstants.ONE_SPACE);
+                column.setWidth(column.getPreferredWidth());
                        }
                }
                int width = 
Math.min(table.getColumnModel().getTotalColumnWidth(), 
(int)(WindowUtils.getScreenWidth() * .75));
@@ -170,5 +183,4 @@
                        }
                }
        }
-
 }
\ No newline at end of file


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
spring-rich-c-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spring-rich-c-cvs

Reply via email to