TextLayout: underline : TextLayout « SWT « Java Tutorial

Home
Java Tutorial
1.Language
2.Data Type
3.Operators
4.Statement Control
5.Class Definition
6.Development
7.Reflection
8.Regular Expressions
9.Collections
10.Thread
11.File
12.Generics
13.I18N
14.Swing
15.Swing Event
16.2D Graphics
17.SWT
18.SWT 2D Graphics
19.Network
20.Database
21.Hibernate
22.JPA
23.JSP
24.JSTL
25.Servlet
26.Web Services SOA
27.EJB3
28.Spring
29.PDF
30.Email
31.J2ME
32.J2EE Application
33.XML
34.Design Pattern
35.Log
36.Security
37.Apache Common
38.Ant
39.JUnit
Java Tutorial » SWT » TextLayout 
17.41.8.TextLayout: underlinePrevious/Next
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, 35);

    
    shell.addListener(SWT.Paint, new Listener() {
      public void handleEvent(Event event) {
        Point point = new Point(1010);
        int width = shell.getClientArea().width - * 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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.