Archived

This topic is now archived and is closed to further replies.

[java] Jlabel

This topic is 6418 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i''m trying to animate a jlabel object using setImage() method on the related icon object.To see the animation playing i have to directly call uptdate() evry time component needs to be refreshed.It shouldnt repaint itself automatically when something changes? If i use the setPosition() calling update() isnt necessary and i see the animation displaying correctly. i''ve also tryied a call to JLabel.setIcon() after updating image with IconImage.setImage() but still doesnt work.... anybody can help me? =)

Share this post


Link to post
Share on other sites
I think the default behaviour in Java GUI is that the GUI will not update itself unless it specifically has to (like when a window has been placed on and off the component in question). Solution: call repaint() ( I think invalidate() just calls repaint(), right?) and the component "should" be updated. If you get a hold of the Graphics object you''ll be able to somewhat immediately update the component with the next image in the frameset except that you''ll have to make sure you preserve what you overwrite (if the gui did it for you), something I''m still not sure how to do. You can''t get an Image representation of a component or save the original Graphics context, so there''s the hard part if you pursue that implementation.

joeG

Share this post


Link to post
Share on other sites
The update and repaint methods put the repaint request on a stack, and it's up to the JVM to decide when to actually do the painting. The only way to circumvent this is to call the paintImmediately method of JComponent. So if you've got something like this:

JLabel myLabel = new JLabel(...);

and later you set the image:

myLabel.setIcon(myIcon);

you can then guarantee immediate, instant repainting by doing something like this:

myLabel.paintImmediately(myLabel.getBounds());

This'll repaint the JComponent (a JLabel here) and all of its components right away.

You can also do this:

Rectangle bounds = myLabel.getBounds();
myLabel.paintImmediately(bounds.x, bounds.y, bounds.width, bounds.height);


Edited by - SteveMeister on June 22, 2000 9:10:00 AM

Share this post


Link to post
Share on other sites