Reading the jQuery plugin articles, this code may well not work on all browsers. There appear to be some quirks with IE (what a surprise) and Opera (don't know of that is version specific). I also do not know (I do not have a copy to test it with) whether the IE problems have gone away with IE9.
David On Friday 18 February 2011, Carlo Alberto Degli Atti wrote: > Thx (I'm still learning GWT...) > > ;-) > > On Feb 18, 2:34 pm, David Goodenough <david.goodeno...@btconnect.com> > > wrote: > > When you create the panel and want to render it, use:- > > > > DeferredCommand.addCommand( new Command( ) { > > public void execute() { > > textArea.rightSize( ); > > } > > }); > > > > where textArea is the ExpandableTextArea. > > > > David > > > > On Friday 18 February 2011, Carlo Alberto Degli Atti wrote: > > > David it works (gwt2.2). > > > > > > But how can I set the height at rendering time (before any browser > > > event)? > > > > > > On Feb 18, 1:53 pm, David Goodenough <david.goodeno...@btconnect.com> > > > > > > wrote: > > > > I have not tried it on a RichTextArea, but the principle should work > > > > on those too. > > > > > > > > David > > > > > > > > On Friday 18 February 2011, Carlo Alberto Degli Atti wrote: > > > > > Hi David, > > > > > > > > > > thank you for your answer! I will try it and I will give you my > > > > > feedback :-) > > > > > > > > > > In my case the width is not a problem; my concern is about the > > > > > height (the number of displayed rows)... > > > > > > > > > > best regards, > > > > > > > > > > CA > > > > > > > > > > On Feb 18, 1:11 pm, David Goodenough > > > > > <david.goodeno...@btconnect.com> > > > > > > > > > > wrote: > > > > > > On Friday 18 February 2011, Carlo Alberto Degli Atti wrote:> Hi, > > > > > > > > > > > > > I've looked around but I haven't found any solution, so I post > > > > > > > it here: > > > > > > > > > > > > > > how can I make a TextArea that expands its height depending on > > > > > > > the text inside? > > > > > > > > > > > > > > Thanks > > > > > > > > > > > > > > CA > > > > > > > > > > > > Its good to find someone else who wants this. I first came > > > > > > across fields like this with Lotus Notes, which has had these > > > > > > for years. They are really useful, but very few other systems > > > > > > seem to have them and to be honest it is one of the things that > > > > > > puts me off browsers - but that is another story. > > > > > > > > > > > > I wrote some code which did this while ago, but I do not know if > > > > > > it still works on a current GWT, and I am absolutely sure it can > > > > > > be done better. > > > > > > > > > > > > import com.google.gwt.user.client.Element; > > > > > > import com.google.gwt.user.client.Event; > > > > > > import com.google.gwt.user.client.ui.TextArea; > > > > > > > > > > > > public class ExpandingTextArea extends TextArea { > > > > > > public void onBrowserEvent( Event event) { > > > > > > super.onBrowserEvent( event); > > > > > > if (getOffsetHeight( ) <= getScrollHeight( > > > > > > getElement( ))) setHeight( ( getScrollHeight( > > > > > > getElement( )) + 6)+"px"); } private native int getScrollHeight( > > > > > > Element e) /*-{ return e.scrollHeight; > > > > > > }-*/; > > > > > > public void rightSize( ) { > > > > > > Element el = getElement( ); > > > > > > int h = getScrollHeight( el); > > > > > > setHeight( ( h + 6) + "px"); > > > > > > } > > > > > > }; > > > > > > > > > > > > The fact that it has a magic number in it (6) is just plain > > > > > > wrong, and I can not for the life of me remember why that number > > > > > > is there. > > > > > > > > > > > > rightSize needs to be called when laying out a form, just to get > > > > > > started. Again this can be done better. It is also possible that > > > > > > somewhere along the line the need for getScrollHeight has gone, > > > > > > but I have not been following the API closely enough to see. > > > > > > > > > > > > To get the full Notes function, one would also need to set the > > > > > > width of the area. This only sets the height. But that is for > > > > > > another day. > > > > > > > > > > > > Hope someone can turn this into something that works properly. > > > > > > > > > > > > David -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To post to this group, send email to google-web-toolkit@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.