Re: drawString result intersects existing lines- any way to make the text opaque?
Monday, February 24, 2003 07:05 AM
I am not quite clear on what your expected result would be. But I am guessing having the lines appear as if they are going under the bounding box for the text is what you are after. If so, you will need add
some code to your paintComponent () method to draw this
box just prior to calling drawString. To do this, you need to:
Draw your lines as you do today
Figure out the bounding box for your text (see the manual
pages for Font and LineMetrics, you may also want to research the TextLayout class as it could simplify
Pick the proper color for the box and set it by calling graphics.setColor (). Picking the same color as the background of the JPanelwould make the bounding box
Draw the rectangle with the bounds you determine in the above by
calling the graphics.fillRect ().
draw you string as you do now today.
In any case, remember that drawString () will only draw the
pixels for the text characters themselves. It does not give you a background for the text.