Friday 15 June 2012

java - Image panel not repainted unless on system events -


One of my friends asked me to help with the swing, and I reached a point where I got an issue Can not solve So, first I have an image panel

  public class ImagePanel JPanel {Private image img; Public Zero Setizes (String Image) {setImage (New Imaging (IMG) .getImage ()); } Public Zero Set Image (Image Image) {Int width = this.getWidth (); Int height = (int) (((double) img.getHeight (faucet) / img.getWidth (faucet)) * width); This.img = img.getScaledInstance (width, height, image. SCALE_SMOOTH); } @ Override PublicWhite Paint Comonant (Graphics G) {g.drawImage (IMG, 0, 0, empty); }}  

and a file chooser , where the selected image should be opened in the image panel. It simply calls setImage to ImagePanel . But the image has not been painted.

However, the image is depicted when the size of JFrame changes (using the mouse). Therefore, the question is, what method is called resizing (using the mouse), which successfully repainted the ImagePanel .

The icon is using the image media tracker to load the image asynchronously. At that point where you are calling again, invalid, etc., the image is not loading.

In your paint, replaced

  g.drawImage (IMG, 0, 0, faucet);  

with

  g.drawImage (IMG, 0, 0, this);  

In the component class, there is an implementation of Image Observer, which will re-color the image when it is loaded.


No comments:

Post a Comment