Hi

I can reasonably easily fix this (patch attached) and I don't seem to be
breaking anything else (tested with KitchenSink).

Is this patch acceptable?

Thanks, Noel.

Todd Volkert wrote:
> It has something to do with needing to know its break width so it knows
> where to wrap and thus how tall it should be.  Greg's the TextArea expert,
> so he can elaborate.
>
> On Wed, Nov 18, 2009 at 7:06 AM, Noel Grandin <noelgran...@gmail.com> wrote:
>
>   
>> Hi
>>
>> I note that TextAreaSkin returns [0,0] in getPreferredSize().
>>
>> Is there a reason for this behaviour?
>> I was trying to use TextArea as a renderer for my variableRowHeight
>> TableView, but without a real preferredSize it doesn't work too well.
>>
>> Thanks, Noel.
>>
>>     
>
>   

Index: TextAreaSkin.java
===================================================================
--- TextAreaSkin.java   (revision 881729)
+++ TextAreaSkin.java   (working copy)
@@ -714,6 +714,7 @@
                 // Add the row views to this view, lay out, and calculate 
height
                 int x = 0;
                 int height = 0;
+                int maxRowWidth = 0;
                 for (int i = 0, n = rows.getLength(); i < n; i++) {
                     row = rows.get(i);
                     row.y = height;
@@ -732,6 +733,8 @@
 
                         nodeView.setLocation(x, y + height);
                         x += nodeView.getWidth();
+                        
+                        maxRowWidth = Math.max(maxRowWidth, x + 
nodeView.getWidth());
 
                         add(nodeView);
                     }
@@ -757,7 +760,7 @@
                 // Ensure that the paragraph is visible even when empty
                 height = Math.max(height, terminatorBounds.height);
 
-                setSize(breakWidth, height);
+                setSize(maxRowWidth, height);
             }
 
             super.validate();
@@ -1471,7 +1474,18 @@
 
     @Override
     public int getPreferredWidth(int height) {
-        return 0;
+        int preferredWidth;
+        
+        if (documentView == null) {
+           preferredWidth = 0;
+        } else {
+            documentView.setBreakWidth(Integer.MAX_VALUE);
+            documentView.validate();
+
+            preferredWidth = documentView.getWidth() + margin.left + 
margin.right;
+        }
+        
+        return preferredWidth;
     }
 
     @Override
@@ -1493,7 +1507,19 @@
 
     @Override
     public Dimensions getPreferredSize() {
-        return new Dimensions(0, 0);
+        int preferredHeight;
+        int preferredWidth;
+        if (documentView == null) {
+           preferredWidth = 0;
+           preferredHeight = 0;
+        } else {
+            documentView.setBreakWidth(Integer.MAX_VALUE);
+            documentView.validate();
+
+            preferredHeight = documentView.getHeight() + margin.top + 
margin.bottom;
+            preferredWidth = documentView.getWidth() + margin.left + 
margin.right;
+        }
+        return new Dimensions(preferredWidth, preferredHeight);
     }
 
     @Override

Reply via email to