Skip to main content

Fade effect

4 replies [Last post]
stevenmwall
Offline
Joined: 2007-06-18
Points: 0

I just started playing around with the Timing Framework and while I know how to move, re-size components, is there a way to have a component "fade" out? Ultimately, what I would like to do is have the button the user just clicked fade away and then add some other components to the screen.

Thanks in advance.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rah003
Offline
Joined: 2004-05-26
Points: 0

In order to fade out some component it has to slowly blend in the background. This can be achieved by changing alpha channel of the color of the component. Or even better you can use JXPanel from swingx as a base container for your component and use its alpha property as a target for animation.
[code]
JXPanel component = new JXPanel();
PropertySetter modifier = new PropertySetter(component, "alpha", 1f, 0f);
Animator timer = new Animator(500, modifier);
...
[/code]

HTH
Jan

jackdog
Offline
Joined: 2005-09-16
Points: 0

I have to hijack, but what if we took this one step further and allowed a component to be fading both ways while being toggled off the EDT.

Say you press a button and a component plans to fade out over 10 seconds. While that time is elapsing - say 3 seconds in, the button is hit again causing the component to fade back in starting from the current 3 seconds (as opposed to 10) and falling back to zero.

Is there a clever, thread safe way to do this with this framework?

rah003
Offline
Joined: 2004-05-26
Points: 0

Easy. Keep reference to your animator, when action is executed you check whether it is already running. If not you start it (that's when button is pressed first time, or animation finished already). If animator is already running, you know what it is executing so you just stop it, reverse (to start from wherever it was at the moment) and restart it. There is something along those lines in the examples.

chet
Offline
Joined: 2003-08-07
Points: 0

This approach is already used internally for "auto-reversing" Triggers. You can either use a Trigger to get this effect (check out the examples to see how it's done) or check out the code inside Triggers to see how it's done. (Hint: use setStartFraction() and setStartDirection()).

Chet.