Remarks Text : Text « SWT JFace Eclipse « Java

Remarks Text

Remarks Text

 * All Right Reserved. 
 * Copyright (c) 1998, 2004 Jackwind Li Guojie
 * Created on Feb 17, 2004 9:58:26 PM by JACK
 * $Id$

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class RemarksText {
  Display display = new Display();
  Shell shell = new Shell(display);
  Text text;

  public RemarksText() {
    shell.setLayout(new GridLayout(1, false));
    (new Label(shell, SWT.NULL)).setText("Remarks:");
    text = new Text(shell, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    text.setLayoutData(new GridData(GridData.FILL_BOTH));
    System.out.println("getText: " + text.getText(1, 6));
    char[] chars = text.getLineDelimiter().toCharArray();
    for (int i = 0; i < chars.length; i++) {
      System.out.println("Line delimiter #" + i + ": " + Integer.toHexString(chars[i]) );
    System.out.println("Number of chars: " + text.getCharCount());
    System.out.println("Tabs: " + text.getTabs());
    text.addVerifyListener(new VerifyListener() {
      public void verifyText(VerifyEvent e) {
        if(e.end == e.start) {
          if( e.character == ' ' && (e.stateMask & SWT.CTRL) != 0 ) {
            if(text.getText(e.end-1, e.end-1).equals("V")) {
              e.text = "erifyListener";
              e.doit = false;
    text.addModifyListener(new ModifyListener() {
      public void modifyText(ModifyEvent e) {
        System.out.println("New character count: " + text.getCharCount());  
    // text.append("a");
    text.setSelection(1, 4);
    System.out.println("getSelection:\t" + text.getSelection());
    System.out.println("getSelectionCount:\t" + text.getSelectionCount());
    System.out.println("getSelectionText:\t" + text.getSelectionText());

    // shell.pack();
    shell.setSize(300, 150);;

    // Set up the event loop.
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        // If no more entries in event queue


  private void init() {


  public static void main(String[] args) {
    new RemarksText();


Related examples in the same category

1.Text to uppercase
2.Text EventText Event
3.Text and Label demoText and Label demo
4.Wrap LinesWrap Lines
5.Demonstrates text fieldsDemonstrates text fields
6.Demonstrates multiline comments
7.Turns e characters red using a LineStyleListenerTurns e characters red using a LineStyleListener
8.TextField Example 5TextField Example 5
9.TextField Example 4
10.TextField Example 3TextField Example 3
11.TextField Example 2TextField Example 2
12.TextField ExampleTextField Example
13.SWT XML Editor: Modify DOMSWT XML Editor: Modify DOM
14.Draw internationalized styled text on a shellDraw internationalized styled text on a shell
15.Detect when the user scrolls a text controlDetect when the user scrolls a text control
16.Verify input (format for date)Verify input (format for date)
17.Verify input (only allow digits)Verify input (only allow digits)
18.Set the selection (start, end)Set the selection (start, end)
19.Text example snippet: set the selection (i-beam)Text example snippet: set the selection (i-beam)
20.Select all the text in the controlSelect all the text in the control
21.Resize a text control (show about 10 characters)Resize a text control (show about 10 characters)
22.Prompt for a password (set the echo character)Prompt for a password (set the echo character)
23.Stop CR from going to the default buttonStop CR from going to the default button
24.Add a select all menu item to the controlAdd a select all menu item to the control
25.Detect CR in a text or combo control (default selection)Detect CR in a text or combo control (default selection)