wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes backgroundColor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "backgroundColor" Watch "backgroundColor" New topic


michael huang
Ranch Hand

Joined: Jul 30, 2000
Posts: 63
hi all,
when i look at the API doc, i found Graphics has two method: fillRect(), clearRect(). fillRect() use current Color and clearRect() use backgroundColor, i can use setColor() set current Color, how can i set backgroundColor? where is the backgroundColor?
Stephanie Grasson
Ranch Hand

Joined: Jun 14, 2000
Posts: 347
I found this in the Java 2 specs:
public abstract void clearRect(int x,
int y,
int width,
int height)

Clears the specified rectangle by filling it with the background color of the current drawing surface. This operation does not use the current paint mode.
Beginning with Java 1.1, the background color of offscreen images may be system dependent. Applications should use setColor followed by fillRect to ensure that an offscreen image is cleared to a specific color.
Hope this helps.
michael huang
Ranch Hand

Joined: Jul 30, 2000
Posts: 63
Stephanie, thanks a lot
is that means background color depend on system, you can not set?
and what is the current paint mode, that means paint()?
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Michael,
There is a setBackground() method for Components. You could use it to set the background color of the object containing the rectangle.
Hope that helps.

Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport

Joined: Sep 09, 2000
Posts: 4
Dear Friend,
You can use the setBackground(Color.___) method to set the background for any GUI control components,frames, etc..

michael huang
Ranch Hand

Joined: Jul 30, 2000
Posts: 63
I C,
i'll test it

It is sorta covered in the JavaRanch Style Guide.
subject: backgroundColor
Similar Threads
Get Area of a Polygon
Question about repainting
Dynamically change tab color JTabbedPane
How to set the background color of check box?