TextLayout: underline : TextLayout « SWT « Java Tutorial






TextLayout: underline
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.TextLayout;
import org.eclipse.swt.graphics.TextStyle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;

public class TextLayoutUnderline {

  public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.DOUBLE_BUFFERED);
    shell.setText("Underline, Strike Out");
    Font font = shell.getFont();
    String text = "text.text.text.";
    final TextLayout layout = new TextLayout(display);
    layout.setText(text);
    TextStyle style1 = new TextStyle(font, null, null);
    style1.underline = true;
    layout.setStyle(style1, 3, 5);

    
    shell.addListener(SWT.Paint, new Listener() {
      public void handleEvent(Event event) {
        Point point = new Point(10, 10);
        int width = shell.getClientArea().width - 2 * point.x;
        layout.setWidth(width);
        layout.draw(event.gc, point.x, point.y);
      }
    });
    
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }
    layout.dispose();
    display.dispose();
  }
}








17.41.TextLayout
17.41.1.TextLayout: Font, Style and ColorTextLayout: Font, Style and Color
17.41.2.TextLayout UnicodeTextLayout Unicode
17.41.3.Draw wrapped text using TextLayoutDraw wrapped text using TextLayout
17.41.4.TextLayout: using TextLayout justify, alignment and indentTextLayout: using TextLayout justify, alignment and indent
17.41.5.Subscript and superscript: using the rise field of a TextStyleSubscript and superscript: using the rise field of a TextStyle
17.41.6.Embed image and controls in TextLayoutEmbed image and controls in TextLayout
17.41.7.TextLayout: strikeoutTextLayout: strikeout
17.41.8.TextLayout: underlineTextLayout: underline