[cp-patches] FYI: TableColumn.sizeWidthToFit() implemented

David Gilbert david.gilbert at object-refinery.com
Wed Mar 15 14:16:14 UTC 2006


This patch (committed) implements the TableColumn.sizeWidthToFit() method, which was 
previously stubbed:

2006-03-15  David Gilbert  <david.gilbert at object-refinery.com>

	* javax/swing/table/TableColumn.java
	(sizeWidthToFit): Implemented.

I committed Mauve tests to back up the implementation already.

Regards,

Dave
-------------- next part --------------
Index: javax/swing/table/TableColumn.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/table/TableColumn.java,v
retrieving revision 1.20
diff -u -r1.20 TableColumn.java
--- javax/swing/table/TableColumn.java	15 Mar 2006 11:54:29 -0000	1.20
+++ javax/swing/table/TableColumn.java	15 Mar 2006 14:12:47 -0000
@@ -38,6 +38,8 @@
 
 package javax.swing.table;
 
+import java.awt.Component;
+import java.awt.Dimension;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
 import java.io.Serializable;
@@ -584,11 +586,23 @@
   }
 
   /**
-   * sizeWidthToFit
+   * Sets the minimum, maximum, preferred and current width to match the
+   * minimum, maximum and preferred width of the header renderer component.
+   * If there is no header renderer component, this method does nothing.
    */
   public void sizeWidthToFit()
   {
-    // TODO
+    if (headerRenderer == null)
+      return;
+    Component c = headerRenderer.getTableCellRendererComponent(null, 
+        getHeaderValue(), false, false, 0, 0);
+    Dimension min = c.getMinimumSize();
+    Dimension max = c.getMaximumSize();
+    Dimension pref = c.getPreferredSize();
+    setMinWidth(min.width);
+    setMaxWidth(max.width);
+    setPreferredWidth(pref.width);
+    setWidth(pref.width);
   }
 
   /**


More information about the Classpath-patches mailing list