That works perfect. Thank you!
testImg.addLoadHandler(new LoadHandler() {
public void onLoad(LoadEvent event) {
System.out.println(" testImg.addLoadHandler(): width" +
testImg.getWidth());
}
});
Brandon Donnelson
http://gwt-examples.googlecode.com
On Mar 23, 2:13 pm, Philip Rogers <[email protected]> wrote:
> Did you try using the onload event in GWT, like you did in the JS?
>
> For example:
> public class MyTest implements EntryPoint {
> public void onModuleLoad() {
> final Image testImg = new Image("http://i.cdn.turner.com/
> cnn/.element/img/3.0/global/header/hdr-main.gif?nocache=" +
> Math.random());
> RootPanel.get().add(testImg);
> printImageWidth(testImg); // will print 0
> testImg.addLoadHandler(new LoadHandler() {
> public void onLoad(LoadEvent event) {
> printImageWidth(testImg); // will print a number
> }
> });
> }
>
> public void printImageWidth(Image image) {
> System.out.println("image width is: " + image.getWidth());
> }
>
> }
>
> On Mar 23, 12:30 pm, Brandon Donnelson <[email protected]>
> wrote:
>
>
>
>
>
>
>
> > Is there a way to get the width via the java code? I've documented it
> > and made an issue:
>
> > Issue:http://code.google.com/p/google-web-toolkit/issues/detail?id=3999&can...
>
> > Getting images size width and height attributes does not work in GWT
> > Image.
>
> > GWT 2.2.0, Mac OSX, Chrome 10.0.648.151
>
> > This will not work:
>
> > Image testImg = new Image("/images/test.jpg");
>
> > FlowPanel panel = new FlowPanel();
> > RootPanel.get().add(panel);
> > panel.add(testImg);
>
> > System.out.println("testImg.getElement.getOffsetWidth=" +
> > testImg.getElement().getOffsetWidth()); // nope
> > System.out.println("testImg.getWidth=" + testImg.getWidth()); //
> > nope
>
> > System.out.println("panel.getOffsetWidth()=" +
> > panel.getOffsetWidth()); // gets the windows/document/body width if
> > image overflows
> > System.out.println("panel.getOffsetHeight()=" +
> > panel.getOffsetHeight()); // gets the windows/document/body width if
> > the image overflows
> > System.out.println("root width:" +
> > RootPanel.get().getOffsetWidth()); // gets the windows/document/body
> > width width if the image overflows
>
> > This does work in native javascript:
> > <script>
> > function getWidthAndHeight() {
> > alert("'" + this.name + "' is " + this.width + " by " + this.height
> > + " pixels in size.");
> > return true;}
>
> > function loadFailure() {
> > alert("'" + this.name + "' failed to load.");
> > return true;}
>
> > var myImage = new Image();
> > myImage.name = "/images/test.jpg";
> > myImage.onload = getWidthAndHeight;
> > myImage.onerror = loadFailure;
> > myImage.src = "/images/test.jpg";
> > </script>
>
> > Brandon Donnelsonhttp://gwt-examples.googlecode.comhttp://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.