Re: Fade out Swing components
This doesn't work for me. I have a JLabel component and it should
fade out to the background color of the underlying frame.
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>,
Andre Rothe <aro...@phosco.info> wrote:
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>