JDK-4170060 : Lightweight component - clearRect does not draw background color
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.2.0
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_2.6
  • CPU: sparc
  • Submitted: 1998-08-28
  • Updated: 1999-10-27
  • Resolved: 1999-10-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.3.0 kestrelFixed
Related Reports
Relates :  
Description
I am writing a library of lightweight components for testing purposes
and have one app using them to test with so far.

The widget hierarchy is

  Frame
   containing a LWResizable (extends Container)
     containing LWLabels (extends Component)

Each widget has a different background color which should allow me
to see where each is more clearly.

According to documentation I should have the paint() method of
the widgets do something like

  paint() {
    g.clearRect(0, 0, dim.width, dim.height);
    g.setColor(getForeground());
    ... drawing for the contents of the widget...
  }

However with lightweights, this does not draw the background color
of the lightweight.  Instead the background color of the heavyweight
(frame) at the top level is drawn.

Interesting effects also occur as you modify which widget is heavy
or light weight.

This behavior exists in 1.1.6 and 1.2beta4.

Instructions for using the demo app:
The LWResizable widget draws for squares at its corners and tracks mouse
motion such that it resizes its contents to match mouse movements.  You click
on a corner and drag, and that resizes the container.

Information is printed on stdout as you use the app.  Note especially
that in the paint functions, that the bgColor of the widget is as
expected, but that's not what is drawn.

The app is in test/layout.  A shell script is in test/layout for
setting up environment.  The widget classes are in lw.  And finally
a makefile in test/layout lets you do 'make clean' and 'make' to
ensure everything is built.

To see the bug you edit lw/LWButton.java, and in the paint method there
are three lines of interest:


    super.paint(g);
    g.clearRect(0, 0, dim.width, dim.height);
    //g.fillRect(0, 0, dim.width, dim.height);

With the g.fillRect call commented out, the LWButton is painted with a
green color, and with the super.paint/g.clearRect commented out
the button is painted with a red color.

Note:  The toplevel Frame has green background, the LWResizable has
white background, and LWButton has red background (all set via
setBackground calls in their respective constructors).

According to the documentation, calling clearRect in LWButton.paint should
cause the LWButton to be red.

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: generic FIXED IN: kestrel INTEGRATED IN: kestrel VERIFIED IN: kestrel-beta
14-06-2004

WORK AROUND Change paint method to use g.setColor() and g.fillRect() paint() { g.setColor(getBackground()); g.fillRect(0,0,dim.width,dim.height); g.setColor(getForeground()); ... drawing for contents... } That works fine. This is the workaround.
11-06-2004

PUBLIC COMMENTS This is incompletely fixed. See 4285515 for an RFE covering the missing functionality breakage.
10-06-2004

EVALUATION This bug is fixable only for Graphics2D and PrintGraphics objects. Graphics2D has a setBackground() method which controls the background color used in clearRect(). There is no way to change the backround color for a Graphics. I have fixed the bug for these two cases. david.mendenhall@eng 1999-10-10 No regression test provided. Existing SQE test for 4258648 verifies fix. david.mendenhall@eng 1999-10-26
10-10-1999