Guillermo
Guillermo

Reputation: 97

Image.setIcon(Parameters) Is not refreshing the Label

I'm working with Java Swing in the making of an Online Chess(Client-Server), I have been able to make the chessTable form wonderfully with no trouble, but in the lobby I'm showing the user's Avatar, the problem is that, the user is able to change his avatar through the server, but when ever I call the setIcon of the new image, it wont refresh it.

Explanation:

The users start with a default image(Avatar.jpg) downloadead from the server,if he changes it, the server sends to the client the new image he chose with the same name of the previous one, so it gets replaced. But when ever i call setIcon of this new image(after the download), it wont do anything and the Label stick to show the first image he ever set. I'm checking the folder and the image are being sent form the server to the client with out problems, and the only way for me to make the client refresh the Avatar is by closing and opening the app. Any ideas?, I tried reprint every random thing I could find still no solution, and the labels refresh by a clickedListener. I use this line to set the image:

this.JLProfilePic.setIcon(new javax.swing.ImageIcon(getClass().getResource("/View/Images/avatar.jpg")));   

Edit1: I'm not working with a JApplet, still I don't have any idea of where the problem might be originated, since Im able to change the Label Icon to any image but when ever I try to change the Icon to Avatar, it still shows the previous one even if in the folder you can see that Avatar.jpg is not the same, it changed for a new one.

Edit2: Well I still haven't found any solutions for this, I supose might be true or not, since i setIcon once, the image is saved at the cache when ever the program re access to the same image it goes to the cache instead of checking again the source of the file. Not sure but is the only Logic I can make.

Upvotes: 0

Views: 428

Answers (1)

Kumar Vivek Mitra
Kumar Vivek Mitra

Reputation: 33534

Try this,

Image img = ImageIO.read(new URL("http:\Server_IP:Port\image.jpg"));

setIconImage(img);

Upvotes: 1

Related Questions