Image.setIcon(Parameters) Is not refreshing the Label - java

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.

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

Related

How can I save an image, change the contrast/brightness, display the change then restore the original image, displaying those all in the same window?

The idea of my program is similar to the adjust brightness/contrast built-in plugin. I want to have the image in one window where you can see it with varying b/c values.
The original image should be saved before I make any changes to it so that I can go back to the original and make more changes to that instead of the new image created after using the setDisplayRange(), which revert the b/c settings back to how they were in the original. This should all happen in the same window. I don't want to create a new window each time to display the changes I make.
ImagePlus imp = WindowManager.getCurrentImage();
ImageProcessor ip = imp.getProcessor();
ip.snapshot();
imp.setDisplayRange(10, 30);
Thread.sleep(1000);
ip.reset();
Reading the API, I believe this should work and do what I want but it only changes the b/c without going back to what the original image was. I looked at the b/c code and this is seems to be what they did there too so I'm not sure what's really wrong here unless I am making a stupid mistake, misunderstanding what the snapshot and reset methods do?
Any help would be appreciated, thank you in advance.

Getting 'with_frame(":1")' in my tests

My app has the ability to 'load' a deal. After it's loaded, a new frame renders with the deal's information.
I'm having trouble targeting this frame with Marathon. I am able to target other parts of the app, but if I control-click on the new frame, I get with_frame(":1") in my scripts. When I try to replay, Marathon cannot identify the frame, and hangs.
I surmise it has something to do with a name or id attribute on the panel, though I don't know much about Java. Could someone point me in the right direction?
#DanielDiazCarrete was correct, I added
this.setTitle("SomeTitle");
to my frame, and Marathon was able to identify it.

I am having troubles displaying a View as a popup window for a ToS

First post here, sorry if I do(did?) something wrong.
I have been developing an android application for a few weeks now and decided to add a User Agreement/Terms of Service to it. I created an xml called agreement.xml, and found this code...
https://gist.github.com/slaypni/3817116
(I found it on here somewhere actually but I couldnt find the original, this one is extremely similar, just a different class name.)
This worked perfectly for me for awhile but I recently altered a little bit of the code that calls it and tested on a new device and there is a strange issue.
I call it via...
View licenseView = View.inflate(UI, R.layout.agreement, null);
PopUpView ToS = new PopUpView(UI, licenseView);
ToS.show();
I run the code once on first application execution (and alter a few things such as button text and visibilities) to collect some user information. I then call it again after everything is done to display the newly downloaded agreement. The second time around it appears that none of the following code is working.
checkboxAcceptLicense = (CheckBox)UI.findViewById(R.id.checkLicenseAgreement);
textviewLicense = (TextView)UI.findViewById(R.id.textviewLicenseAgreement);
textviewLicense.setText(agreement);
buttonOK= (Button)UI.findViewById(R.id.buttonOK);
buttonCancel = (Button)UI.findViewById(R.id.buttonCancel);
etName = (EditText)UI.findViewById(R.id.etName);
etNumber = (EditText)UI.findViewById(R.id.etNumber);
etName.setText(prefs.getString("Name", null));
etNumber.setText(prefs.getString("Number", null));
buttonCancel.setOnClickListener(cancel);
buttonOK.setOnClickListener(accept);
which immediately follows the first block. I assume the issue is with the class I am using to display the item as a popup as I had some strange null pointer exceptions from it before. Currently there are no errors or anything, the code runs and the logging all around it shows up but the buttons are unresponsive and the text isnt set.
Thanks for any and all help!
Edit: I removed my null check because I assume this is evidence of the problem. On the second call it crashes with a nullpointerexception at line 74 of the popup class. I feel like it is a problem with the inflater but I really do not have a clue.
you can try to make a dialog instead it comes with a positive and negative buttons (ok/cancel)
and a content area which you can customize as you need check out this LINK

Adding icon to my application issues

I want to change the icon of my application. system.gif is in current directory. getDefaultToolkit() is not working. getToolkit() is working but another minimized window is also open. Other components are Swing components.
Toolkit theKit = jtfMainFrame.getDefaultToolkit();
Image icon = theKit.getImage("system.gif");
To get an icon for an app.
Add it to the Jar and use Class.getResource("/system.gif") to obtain an URL to it. File objects will generally not work for such an 'application resource'.
To load the image, use ImageIO.read(URL). This is a blocking method that will ensure the image is entirely loaded before proceeding. It will also throw informative exceptions if anything goes wrong.

OfficeBean won't display after moving containing Swing Panel from one Container to another

I'm developing a Java 6 applet which allows users to view OO (v.3.2) documents (read only), and if they choose, click a button which launches a new JDialog window, with the document displayed in it which allows the user to and mark and redact it as they wish. Once they are done, they can close the JDialog, which saves the document to a server and redisplay the updated document (read-only again) in the original applet window
I guessed that I could do this with a single instance of an OfficeBean, embedded in a Swing Panel. However, I cannot seem to successfully move my Panel (containing the OfficeBean) from the applet to the JDialog when the "Redact" button is clicked. All I get is a blank area in the JDialog where the document should be. I get no errors.
I have currently managed to get round this by creating new instances of the OfficeBean every time I need to display the document (once when the applet is loaded, again when the user chooses to redact and it is opened in a JDialog, and finally when they click "Save" in the dialog and the redacted result is displayed in the applet again.) However this means three trips to and from the server where the documents originate. That seems mad to me.
I'm in no way a Swing expert and may well be making a silly mistake. However, I've done a lot of fiddling around, debugging and googling and can't seem to get this to work. Can anyone help me in this? Am I trying to do something which is fundamentally impossible? I hope not.
One rule in Swing is that a component can only be displayed / attached to one part of the gui "tree" at a time. When you "move" your component to the dialog, are you first removing it from the applet?

Categories