Hello there,
I've got a JPanel on which I draw GeneralPaths.
As it's a bit too complex sometimes,
I'd like to clean the JPanel on which I draw
before I draw a new GeneralPath...
The code below shows my current solution...
<CODE>
super.paintComponent(g);
((Graphics2D) g).scale(zoom, zoom);
g.setColor(Color.white);
g.clearRect(0, 0, 800, 600);
double dummy = width / (2 * Math.PI + Double.MIN_VALUE);
BasicStroke simple = new BasicStroke((float) (1 / dummy));
((Graphics2D) g).setStroke(simple);
((Graphics2D) g).setColor(new Color(128, 128, 128));
((Graphics2D) g).draw(grid);
((Graphics2D) g).draw(door);
((Graphics2D) g).setColor(Color.blue);
((Graphics2D) g).draw(path);
</CODE>
What's wrong with that?
I also tried fillRect instead of clearRect,
but it didn't worked, either.
Kindest regards
Adrian
Thomas Weidenfeller - 04 Feb 2005 08:09 GMT
> What's wrong with that?
> I also tried fillRect instead of clearRect,
> but it didn't worked, either.
Please do not multi-post. And please, provide us with complete code,
some real problem description, error messages, etc, and not the
meaningless "does not work".
/Thomas

Signature
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
Bill Tschumy - 04 Feb 2005 19:52 GMT
> Hello there,
>
[quoted text clipped - 31 lines]
> Kindest regards
> Adrian
I think fillRect() is now the recommended way to do it (yes, you did indicate
you tried it).
You might try placing the fillRect() before the scale(). After scaling, it
is not clear if filling a (0,0,800,600) rect is really going to clear your
region (I would also use getSize() rather than hardcoding the size).

Signature
Bill Tschumy
Otherwise -- Austin, TX
http://www.otherwise.com