1

I want to render something on my GlassPane. The problem is, that if i move the rendered lines around, the previously rendered pixels have still the same color. I can not use g.clearRect because it doesn`t clears the transparency.

Thats my rendering code:

Graphics2D g2 = (Graphics2D) g;

    for(LinePath line : lines)
    {
        for(int i = 0; i < line.points.length; i+=2)
        {
            if(i != 0)
            {
                g.drawLine((int)line.points[i-2],(int)line.points[i-1],(int)line.points[i],(int)line.points[i+1]);
            }
        }
    }


    //Clearing alpha
    Area area = new Area();
    // This is the area that will filled...
    area.add(new Area(new Rectangle2D.Float(0, 0, getWidth(), getHeight())));
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,0.0f));
    g2.fill(area);

And here is the result: enter image description here

bitQUAKE
  • 473
  • 1
  • 8
  • 19
  • 2
    For better help sooner, post an [MCVE](http://stackoverflow.com/help/mcve) (Minimal Complete Verifiable Example) or [SSCCE](http://www.sscce.org/) (Short, Self Contained, Correct Example). – Andrew Thompson Jun 28 '15 at 15:39

1 Answers1

1

clearRect should work but you have to reset your alpha composite before using it.

Ex:

g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,1.0f));

Josh Marinacci
  • 1,715
  • 1
  • 14
  • 15