Reputation: 1575
Is there a simple way to draw underlined text in draw2d without manually drawing a line under the text?
Upvotes: 0
Views: 1784
Reputation: 1575
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);
}
Upvotes: 2
Reputation: 324108
Use a Font with an underline attribute. Darryl's Visual Font Designer shows how to create a font with this property.
Upvotes: 0