example, you could put view.setImage(image) outside the loadhandler,
and GWT.log("loaded!") inside the loadhandler, and then you should see
"loaded!" in your dev console.
But a loadhandler is not required for loading an image, it's only if
you want to respond to the image being loaded. For example, I'm
working on a GWT app that shows a progress bar until an image gets
loaded, and for that code, I put in a loadhandler on the image that
removes the progress bar in the onLoad() (and I also have an
errorhandler that displays a message and remove the progress bar if
the image fails to get loaded). But if you just want to load an image,
you only need to set the source and add it to the page and it will
load.
I don't actually see anything wrong with your first attempt. Why did
it fail outside of hosted mode?
If you want to load your image ahead of time so it displays
immediately, try Image.prefetch(url).
On Jan 9, 7:40 am, tanteanni <tantea...@hotmail.com> wrote:
> i try to get an image displayed that is retrieved from an url. my first
> (false) attempt was not respecting the asynchronous behavior so it only
> worked in hosted mode:
> "
> Image image = new Image(someURL);
> view.setImage(image);
> "
> but this failed in "real" mode. so i googled around (besides wrong examples<http://examples.roughian.com/index.htm#Listeners~LoadListener> and
> this <http://code.google.com/p/gwt-image-loader/> ) i found the problem: a
> have to listen to load event. So i changed my code to this:
> "
> image = new Image(url);
> image.addLoadHandler(new LoadHandler() {
>
> @Override
> public void onLoad(LoadEvent event) {
> view.setImage(image);
> image.setVisible(true);
> }
> });
> "
> the problem is that the event is never been fired or at least onLoad is
> never executed. I also tried to addHandler before setting url. The url it
> self works fine (browser is displaying the image) and log shows positive
> image response:
> "
> response : HTTP/1.1 200
> Content-Type: image/png
>
> graphdata : [B@12505f5
> "
>
> so how to correctly load/display an image in gwt?
>
> thx in advance
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
No comments:
Post a Comment