Hi,

Just another QADH ( Quick and Dirty Hack ). I don't expect this is up to the 
standard you guys like.

I was playing around with resizing a TableView that is within a ScrollPane 
that is within a SplitPane and realised that I didn't want relative sized 
column widths to shrink to nothing before the horizontal scroll bar kicked in.  
I also wanted to set a minimum width for auto sized column widths (-1) so that 
the header wasn't obscured.

What I did to implement this is attached.

Cheers,

Scott.
Index: TableView.java
===================================================================
--- TableView.java	(revision 815942)
+++ TableView.java	(working copy)
@@ -46,6 +46,7 @@
         private String name = null;
         private Object headerData = null;
         private int width = 0;
+        private int minimumWidth = 0;
         private boolean relative = false;
         private SortDirection sortDirection = null;
         private Object filter = null;
@@ -286,7 +287,25 @@
                 }
             }
         }
+        
+        /** Gets the minimum width the column should be sized to.
+         * 
+         *  @return Minimum width.
+         */
+        public int getMinimumWidth()
+        {
+            return minimumWidth;
+        }
 
+        /** Sets the minimum width the column should be sized to.
+         *
+         *  @param width Minimum width column should be sized to.
+         */
+        public void setMinimumWidth( int width )
+        {
+            minimumWidth = width;
+        }
+
         /**
          * Returns the column's sort direction.
          *
Index: skin/terra/TerraTableViewSkin.java
===================================================================
--- skin/terra/TerraTableViewSkin.java	(revision 815942)
+++ skin/terra/TerraTableViewSkin.java	(working copy)
@@ -148,7 +148,7 @@
                     }
                 }
 
-                preferredWidth += columnWidth;
+                preferredWidth += Math.max( columnWidth, column.getMinimumWidth() );
 
                 // Include space for vertical gridlines; even if we are
                 // not painting them, the header does
@@ -156,6 +156,10 @@
                     preferredWidth++;
                 }
             }
+            else
+            {
+                preferredWidth += column.getMinimumWidth();
+            }
         }
 
         return preferredWidth;
@@ -217,7 +221,7 @@
                     }
                 }
 
-                columnWidths.add(columnWidth);
+                columnWidths.add( Math.max( columnWidth, column.getMinimumWidth() ));
                 fixedWidth += columnWidth;
             }
         }
@@ -231,7 +235,7 @@
             if (column.isRelative()) {
                 int columnWidth = (int)Math.round((double)(column.getWidth()
                     * variableWidth) / (double)relativeWidth);
-                columnWidths.update(i ,columnWidth);
+                columnWidths.update(i , Math.max( columnWidth, column.getMinimumWidth() ));
             }
         }
 

Reply via email to