tags:

views:

310

answers:

2

Is there a simple way to draw underlined text in draw2d without manually drawing a line under the text?

A: 

Use a Font with an underline attribute. Darryl's Visual Font Designer shows how to create a font with this property.

camickr
I think that's for AWT fonts, not SWT fonts. SWT uses a different Font class.
thehiatus
+1  A: 

After a bit of research, it looks like underlined text isn't supported natively in Draw2D since SWT fonts are OS level objects and not every OS supported by SWT supports underlined text. Looks like the best bet is to create a method that draws underlined text manually. Maybe it's something that will get added into SWT later.

Here's what I ended up using (more or less):

private void drawUnderlinedText(GC gc, String string, int x, int y)
{
    Point extent = gc.textExtent(string);
    gc.drawText(string, x, y);
    gc.drawLine(x - 1, y + extent.y - 1, x + extent.x - 1, y + extent.y - 1);
}
thehiatus