Updating a jlabel

29 Dec

You should never call sleep(), or perform any other time-consuming operation, in an event handler.While an event handler is running, no other GUI processing -- which includes other event handling and all painting -- can occur.final JFrame frame = new JFrame(); // Miscellaneous code in here - removed for brevity // Create the Image Thumbnail swing Image and start up with a default image swing Image = new JLabel(); String root Path = new File("")Absolute Path(); update Image(root Path "/images/default.jpg"); // Miscellaneous code in here - removed for brevity right Pane.add(swing Image, Border Layout. LINE_END); If you've gotten this far, the first image is my default.jpg, and once I get the directory and identify the first image in that directory, that's where it fails when I try to update the swing Image.JText Field; import javax.swing.event.* ; import *; import *; import Random; /** * * @author Stephen */ public class Number Game extends JFrame You're defining this as a local variable - not initializing your class level "playerpan" variable. This means that you essentially have no reference to those panels outside the constructor. As for the label update, this is most likely due to this line in your button handler well what i'm trying to do is keep each JPanel separate from the main program and define them there and then do the actions etc from the main.Aside from that, why does player extend JPanel but refer to components in the enclosing class? I know it probilly is not right as i only starting off and don't expect to get the programming standards right. Once the call has been made it goes to the update Score() method and new score then goes to the int2str(); to get it displayable and finaly it suppose to append the new scor to the score JLabel Text(sco); is not updating the panel that is in your frame.

public class App JFrame extends JFrame Thanks for any info, Kin Wong I did some research and was able to solve my problem.Can you post more of your code, there is nothing with what you've posted so far as long as the JLabel is only being created once and Update Components() is being called after the button click event.I agree with Fredrick -- that you've not posted enough information for your question to be answerable and that it may be a reference issue -- that the JLabel you are changing is not the one that is displayed in the program.When I try to display the second image, it doesn't get updated...Here's what I've got so far: private void create And Show GUI() { //Create and set up the window.Hopefully it'll help those who might run into the same problem.Apparently, Swing component repainting is managed by a Repaint Manager class which intercepts all paint requests and calls invoke Later() to process the pending requests on the same dispatch thread.Currently you don't have a reference to that instance to work from.(Whereas you do with the "correction" call that is currently working for you in that handler) If you want to keep the panels as separate classes, I would recommend moving the JLabels that go in those panel into those classes and not have them in your top-level JFrame class. There is no reason that update Score should have to set text on a label that is defined at the JFrame level.I have a combo Box in test class and a few JLabels in sample class.What I'm trying to do to is that whenever I select the combo Box options, i want to update the JLabels in the sample class.