Jump to content

  • Log In with Google      Sign In   
  • Create Account


[java] Jlabel


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 koatto   Members   -  Reputation: 122

Like
Likes
Like

Posted 21 June 2000 - 02:16 PM

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? =)

Sponsor:

#2 joeG   Members   -  Reputation: 172

Like
Likes
Like

Posted 21 June 2000 - 03:06 PM

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

#3 SteveMeister   Members   -  Reputation: 122

Like
Likes
Like

Posted 22 June 2000 - 02:07 AM

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

#4 koatto   Members   -  Reputation: 122

Like
Likes
Like

Posted 22 June 2000 - 11:08 AM

thanks =)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS