drawString result intersects existing lines- any way to make the text opaque?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Barry_Wythoff
Posted On:   Sunday, February 23, 2003 04:08 PM

Hi,
I am using drawString() onto a JPanel with some existing lines. Unfortunately, in the result, the lines are seen to be crossing right through the graphics text characters, even though the strings are drawn later.
Is there any simple way to make the text "opaque" to prettify the result??? I have already tried using:

g2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));


but it didn't have any effect.
Thanks for your kindness,
Barry

Re: drawString result intersects existing lines- any way to make the text opaque?

Posted By:   Bahman_Barzideh  
Posted On:   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
    things).

  • 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
    "invisible".

  • 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.
  • About | Sitemap | Contact