[java] Jlabel

Started by
2 comments, last by koatto 23 years, 10 months ago
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? =)
Advertisement
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
joeG
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
I am a Jedi, like my father before me
thanks =)

This topic is closed to new replies.

Advertisement