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-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
David
DeferredCommand.addCommand( new Command( ) {
public void execute() {
textArea.rightSize( );
}
});
where textArea is the ExpandableTextArea.
public class TextBoxExpandWidget extends Composite {
private HTML h;
private TextBox tb;
public TextBoxExpandWidget() {
VerticalPanel vp = new VerticalPanel();
RootPanel.get().add(vp);
tb = new TextBox();
vp.add(tb);
tb.addKeyUpHandler(new KeyUpHandler() {
public void onKeyUp(KeyUpEvent event) {
setSize();
}
});
initWidget(tb);
h = new HTML();
AbsolutePanel ap = new AbsolutePanel();
RootPanel.get().add(ap);
ap.add(h, -100, -100);
}
private void setSize() {
String s = tb.getText();
s = s.replaceAll("\040", " ");
h.setHTML(s);
System.out.println("s: " + s);
int width = h.getOffsetWidth();
if (width > 50) {
tb.setWidth(width + "px");
}
System.out.println("width=" + width);
}
}
--
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-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
--
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-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
Use $(elem).cur(name, force);