Pixels can't be calculated in a input box, but can be calculated in a panel,
at least from what I can do. I have put together some code to dynamically
expand a textbox. The same could be applied to textarea, adding the height.
I'll have the demo up tomorrow on my site, and I'll do textbox and textarea.
I have code in the sourc, but the google svn is down (unusual).
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);
}
}
Brandon Donnelson
http://gwt-examples.googlecode.com
http://c.gawkat.com
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.