JDK-4285515 : Make Graphics.clearRect work as advertised for plain Graphics (lightweight)
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.1.1,1.3.0
  • Priority: P3
  • Status: Closed
  • Resolution: Won't Fix
  • OS: solaris_7,windows_95
  • CPU: x86,sparc
  • Submitted: 1999-10-27
  • Updated: 1999-10-28
  • Resolved: 1999-10-28
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
See related bug: 4170060

In 4170060 and 4258648 it was found that clearRect does not work in lightweight
components.  It is advertised in the documentation (that is, the specification)
to cause the given rectangle to be painted with the background color.  But
this does not work and has not since before 1.2.2.

For 4170060 and 4258648, AWT engineering fixed this issue for Graphics2D and
PrintGraphics objects, but not regular Graphics.

This RFE is as stated in the Synopsis; to make Graphics.clearRect cause the
given rectangle to be painted with the background color.  This may (probably)
mean(s) moving the Graphics2D.set/getBackground methods to Graphics.

The attachment to 4170060 demonstrates the problem.  To see it one must modify
the lw/LWButton.java source appropriately to whether you want to see the
problem.  When LWButton's paint uses clearRect, then its background gets
painted to the background color of the Frame.  But if it uses setColor/fillRect
then the LWButton's background is correctly painted.  To see it, one runs
the app in test/layout .. you must set your classpath to "../..:.".

As to what to fix & where ...

The documentation in question is Graphics.clearRect.  While this method works
fine for a Canvas (heavy weight) it does not work with a lightweight. 

However, given that the documentation is for Graphics, it would not be proper
to fix this by having lightweights be given a Graphics2D masquerading
as a Graphics.  The fix must be in Graphics itself.

It looks like Component.getGraphics shouldn't get the containers Graphics,
but that there should be a Graphics in LightweightPeer.

Comments
WORK AROUND Change paint method to use g.setColor() and g.fillRect()
11-06-2004

EVALUATION This is a reasonable RFE, although I'm not sure how we could ever fix this. I'm against augmenting the Graphics class; that's why we added the new Graphics2D class. Also, I don't see any problem with the test case for 4170060 even when it's modified to use clearRect instead of fillRect. Marking bug incomplete until I am able to resolve this. david.mendenhall@eng 1999-10-27 The submitter has verified that the test case for 4170060 in fact passes at this point. Given that, he has withdrawn this request for enhancement. Closing as Will Not Fix. david.mendenhall@eng 1999-10-28
28-10-1999