3 Replies Latest reply on Oct 9, 2004 11:29 AM by 807587

    Make images fade in & out?

      Hi, we're redeveloping our application in swing (java 1.4.2).
      When the application is not in use it displays several images on the screen. We want these to smoothly fade in and out (not necessarily synchronised with each other) so as to be more visually appealing.

      Any recommendations on a good technique?
      We don't want to use animated gifs due to the 256-colour limit - is there a way to do this that isn't CPU-intensive? Something we can use with PNGs, for example?

        • 1. Re: Make images fade in & out?
          well perhaps you can override the paint method, which will change the opacity of the image...and maybe use some type of thread or timer to animate that fade in/out affect. Set change the opacity used by the Graphics2D object in a paint method do the following:
               * Set alpha composite.  For example, pass in 1.0f to have 100% opacity
               *  pass in 0.25f to have 25% opacity.
              private AlphaComposite makeComposite(float alpha) {
                  int type = AlphaComposite.SRC_OVER;
                  return (AlphaComposite.getInstance(type, alpha));
               public void paint(Graphics g) {
                        Graphics2D g2d = (Graphics2D) g;
                        // do some painting...
          that should give you some idea.

          good luck!
          • 2. Re: Make images fade in & out?
            Excellent thanks, I'll give it a try soon...
            • 3. Re: Make images fade in & out?
              yep that did the trick, and it's smooth. Thanks