Load AWT-Image in parallel/concurrently, then replace a Placeholder-Image

226 Views Asked by At

I am using FlyingSaucer, an purely java-based XHTML-Renderer which is natively integrated into swing. To display images it provides a ReplacedElementFactory which gets an W3C-DOM-Element and may replace it with an ReplacedElement.

The implementation to display images is to return an java.awt.Image from the ReplacedElementFactory, loaded via ImageIO.read(..), which is then rendered. This means the whole loading is a blocking-operation in the EDT-thread, freezing the UI when loading multiple external images...

I wonder how I can return an awt.Image representing "image is loading", dispatch the loading to a Thread and then, my problem is arriving, replace the returned, already-rendered Placeholder-ImageIsLoading with the actual, loaded image. So are there any possibilities to mutate an existing awt.Image and then force it to repaint/flush/whatever?

Any advice?

1

There are 1 best solutions below

0
On BEST ANSWER

I have built a custom "Image extends Component" and repaint the image when loaded and additionally call FlyingSaucer's relayout-method