Is it possible to fade out SWING components instead of
setVisible(false)?
Thank you for all ideas,
Andre
> Is it possible to fade out SWING components instead of
> setVisible(false)?
Yes, there are several approaches. This example [1] varies the
background's saturation, while this one [2] changes the alpha of the
graphics context's composite.
[1]<http://stackoverflow.com/questions/2124507>
[2]<http://stackoverflow.com/questions/2234020>
--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
int xx = this.getWidth();
int yy = this.getHeight();
g2d.setComposite(AlphaComposite.getInstance(
AlphaComposite.DST_IN,
model.getAlpha()));
g2d.setColor(getBackground());
g2d.fillRect(0, 0, xx, yy);
}
It doesn't fade, it switches from a black rectangle to the label
content.
"model" stores the current alpha value, which is changed correctly
after 300 ms by 0.1f. After a model change, a repaint() is processed.
~Andre
On Jan 26, 8:02 pm, "John B. Matthews" <nos...@nospam.invalid> wrote:
> In article
> <f8a44aaf-3aa9-486d-9a45-e0c93cdda...@w17g2000yqh.googlegroups.com>,
Thanks
Andre
>Is it possible to fade out SWING components instead of
>setVisible(false)?
there is setFade( true );
However, you could concoct such a beast by attaching a timer to force
a periodic repaint, and changing the colours on each cycle to
gradually fade them to the background colour.
You could do it by creating "FadingJButton FadingTextArea etc etc. Or
just have a Fader that you feed a set of components to that it calls
setForeground, setBackground and repaint on with a SwingTimer.
It would remember the original colours and the current colours so it
it bring them all back to life. Remember if you setVisible(false)
then validate, the screen real estate will be recycled for other
components. With your fader, that would not happen till the last
minute when you did a setVisible(false).
--
Roedy Green Canadian Mind Products
http://mindprod.com
To err is human, but to really foul things up requires a computer.
~ Farmer's Almanac
It is breathtaking how a misplaced comma in a computer program can
shred megabytes of data in seconds.
> On Wed, 26 Jan 2011 07:02:21 -0800 (PST), Andre Rothe
> <aro...@phosco.info> wrote, quoted or indirectly quoted someone who
> said :
>
>>Is it possible to fade out SWING components instead of
>>setVisible(false)?
>
> there is setFade( true );
<snip>
OK, I'll take the bait...
In what version of Java, in what object, is there a setFade method ?
I can't find it in version 6 Javadocs.