Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / February 2005

Tip: Looking for answers? Try searching our database.

How to clear JPanel?

Thread view: 
Adrian M. Hanslik - 03 Feb 2005 17:14 GMT
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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.