TextLayout: using TextLayout justify, alignment and indent : TextLayout « SWT « Java Tutorial

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
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Tutorial » SWT » TextLayout 
17. 41. 4. TextLayout: using TextLayout justify, alignment and indent
TextLayout: using TextLayout justify, alignment and indent
/*******************************************************************************
 * Copyright (c) 2000, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
//package org.eclipse.swt.snippets;
/*
 * TextLayout example snippet: using TextLayout justify, alignment and indent 
 *
 * For a list of all SWT example snippets see
 * http://www.eclipse.org/swt/snippets/
 
 * @since 3.2
 */
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.TextLayout;
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 TextLayoutJustifyAlignmentIndent {

  public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.DOUBLE_BUFFERED);
    shell.setText("Indent, Justify, Align");
    String[] texts = {
        "Plans do not materialize out of nowhere, nor are they entirely static. To ensure the planning process is transparent and open to the entire Eclipse community, we (the Eclipse PMC) post plans in an embryonic form and revise them throughout the release cycle.",
        "The first part of the plan deals with the important matters of release deliverables, release milestones, target operating environments, and release-to-release compatibility. These are all things that need to be clear for any release, even if no features were to change.",
        "The remainder of the plan consists of plan items for the various Eclipse subprojects. Each plan item covers a feature or API that is to be added to Eclipse, or some aspect of Eclipse that is to be improved. Each plan item has its own entry in the Eclipse bugzilla database, with a title and a concise summary (usually a single paragraph) that explains the work item at a suitably high enough level so that everyone can readily understand what the work item is without having to understand the nitty-gritty detail."};
    int[] alignments = SWT.LEFT, SWT.CENTER, SWT.RIGHT };
    
    final TextLayout[] layouts = new TextLayout[texts.length];
    
    for (int i = 0; i < layouts.length; i++) {
      TextLayout layout = new TextLayout(display);
      layout.setText(texts[i]);
      layout.setIndent(30);
      layout.setJustify(true);
      layout.setAlignment(alignments[i]);
      layouts[i= layout;
    }
    shell.addListener(SWT.Paint, new Listener() {
      public void handleEvent(Event event) {
        Point point = new Point(1010);
        int width = shell.getClientArea().width - * point.x;
        for (int i = 0; i < layouts.length; i++) {
          TextLayout layout = layouts[i];
          layout.setWidth(width);
          layout.draw(event.gc, point.x, point.y);
          point.y += layout.getBounds().height + 10;
        }
      }
    });
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
        display.sleep();
    }
    for (int i = 0; i < layouts.length; i++) {
      layouts[i].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
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.