title: AlphaComposite Transparency with repaint overlaps into black
body: <p>So I have an image on top of another panel, and that image is transparent so you can see the panel beneath it. What I'm trying to do is use repaint() to fade the image (which is drawn with the drawImage() method in java.awt.Graphics) out until it is completely transparent so you can see the panel beneath it clearly. As of now, the image is just fading into black instead of into a transparent texture.</p>
  
  <p>This is a little bit of my code right now:</p>
  
  <p>paintComponent method:</p>
  
  <pre><code>public void paintComponent(Graphics g)
  {
      super.paintComponent(g);
      float alpha = 1f-(.01f*(float)opcounter);
      Graphics2D g2d = (Graphics2D)g;
      g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_IN, alpha);
      g2d.drawImage(img, 0, 0, null);
  }
  </code></pre>
  
  <p>actionPerformed method that is called for the timer </p>
  
  <pre><code>public void actionPerformed(ActionEvent e)
  {
      opcouner++;
      panel.repaint();
  }
  </code></pre>
  
  <p>Longer (uncondensed) version of my code: (including paintComponent and Mover class for timer)</p>
  
  <pre><code>                            public void paintComponent(Graphics g)
              {   
                  super.paintComponent(g);
                  Dimension framesize = frame.getSize();
                  this.setBounds(0,0,framesize.width, framesize.height-61);
  
                  if (buff)
                  {
                      //this.add(buffer);
                      if (opcounter &lt;= 255)
                      {
                          buffer.setForeground(new Color(250, 250, 250, 0+opcounter));
                      }
                      else 
                      {
                          opcounter = 0;
                          buff = false;
                          hand = true;
                      }
                  }
                  if (hand)
                  {
                      this.add(handson);
                      if (opcounter &lt;= 255)
                      {
                          handson.setForeground(new Color(250, 250, 250, 0+opcounter));
                      }
                      else 
                      {
                          opcounter = 0;
                          hand = false;
                          log = true;
                      }
                  }
                  if (log)
                  {
                      this.add(logic);
                      if (opcounter &lt;= 255)
                      {
                          logic.setForeground(new Color(250, 250, 250, 0+opcounter));
                      }
                      else 
                      {
                          opcounter = 0;
                          log = false;
                          pan = true;
                      }
                  }
                  if (pan)
                  {
                      this.add(panic);
                      if (opcounter &lt;= 255)
                      {
                          panic.setForeground(new Color(250, 250, 250, 0+opcounter));
                      }
                      else 
                      {
                          opcounter = 0;
                          pan = false;
                          first = false;
                          second = true;
                          try
                          {
                              //Thread.sleep(2000);
                          }
                          catch(Exception e)
                          {
                              System.out.println("thread not slept");
                          }
                          System.out.println("opcounter = " + opcounter);
                          black.setVisible(false);
                          handson.setVisible(false);
                          logic.setVisible(false);
                          panic.setVisible(false);
                          tutpic = true;
                      }
                  }
                  if (tutpic)
                  {
                      if (opcounter &lt;= 200)
                      {
                          Graphics2D g2d = (Graphics2D)g.create();
                          float alpha = 1f-(.01f*(float)opcounter);
                                            g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_IN, alpha));
                          g2d.drawImage(tut, 0, 0, null);
                          g2d.dispose();
                      }
                      else
                      {
                          opcounter = 0;
                          tutpic = false;
                      }
                  }
              }
  
              class Mover implements ActionListener
              {
                  public void actionPerformed(ActionEvent e)
                  {
                      if (!tutpic)
                          opcounter+=4;
                      else
                      {
                          opcounter++;
                      }
                      tutorial.repaint();
                  }   
              }
  </code></pre>
  
  <p>Any help would be appreciated. Thanks!</p>