Demonstrates StyleRanges : StyledText « SWT JFace Eclipse « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
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 » SWT JFace Eclipse » StyledTextScreenshots 
Demonstrates StyleRanges
Demonstrates StyleRanges

//Send questions, comments, bug reports, etc. to the authors:

//Rob Warner (rwarner@interspatial.com)
//Robert Harris (rbrt_harris@yahoo.com)

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

/**
 * This class demonstrates StyleRanges
 */
public class StyleRangeTest {
  private Color orange;
  private Color blue;

  /**
   * Runs the application
   */
  public void run() {
    Display display = new Display();
    Shell shell = new Shell(display);

    // Create colors for style ranges
    orange = new Color(display, 2551270);
    blue = display.getSystemColor(SWT.COLOR_BLUE);

    createContents(shell);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }

    // We created orange, but not blue
    orange.dispose();

    display.dispose();
  }

  /**
   * Creates the main window contents
   
   @param shell the main window
   */
  private void createContents(Shell shell) {
    shell.setLayout(new FillLayout());

    // Create the StyledText
    StyledText styledText = new StyledText(shell, SWT.BORDER);

    // Set the text
    styledText.setText("Go Gators");

    /*
     * The multiple setStyleRange() method // Turn all of the text orange, with
     * the default background color styledText.setStyleRange(new StyleRange(0, 9,
     * orange, null));
     *  // Turn "Gators" blue styledText.setStyleRange(new StyleRange(3, 6, blue,
     * null));
     */

    /*
     * The setStyleRanges() method // Create the array to hold the StyleRanges
     * StyleRange[] ranges = new StyleRange[2];
     *  // Create the first StyleRange, making sure not to overlap. Include the
     * space. ranges[0] = new StyleRange(0, 3, orange, null);
     *  // Create the second StyleRange ranges[1] = new StyleRange(3, 6, blue,
     * null);
     *  // Replace all the StyleRanges for the StyledText
     * styledText.setStyleRanges(ranges);
     */

    /* The replaceStyleRanges() method */
    // Create the array to hold the StyleRanges
    StyleRange[] ranges = new StyleRange[2];

    // Create the first StyleRange, making sure not to overlap. Include the
    // space.
    ranges[0new StyleRange(03, orange, null);

    // Create the second StyleRange
    ranges[1new StyleRange(36, blue, null);

    // Replace only the StyleRanges in the affected area
    styledText.replaceStyleRanges(09, ranges);
  }

  /**
   * The application entry point
   
   @param args the command line arguments
   */
  public static void main(String[] args) {
    new StyleRangeTest().run();
  }
}



           
       
Related examples in the same category
1. Sample Styled TextSample Styled Text
2. Styled Text with highlighted Odd LineStyled Text with highlighted Odd Line
3. Search Style TextSearch Style Text
4. SetLine Background SetLine Background
5. Implements syntax coloring using the StyledText APIImplements syntax coloring using the StyledText API
6. SWT StyledText
7. Text with underline and strike throughText with underline and strike through
8. Setting the font style, foreground and background colors of StyledTextSetting the font style, foreground and background colors of StyledText
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.