Demonstrates LineBackgroundListeners : Event « SWT JFace Eclipse « Java






Demonstrates LineBackgroundListeners

Demonstrates LineBackgroundListeners

//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.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

/**
 * This class demonstrates LineBackgroundListeners
 */
public class LineBackgroundListenerTest {
  // The color to use for backgrounds
  Color red;

  /**
   * Runs the application
   */
  public void run() {
    Display display = new Display();
    red = display.getSystemColor(SWT.COLOR_RED);
    Shell shell = new Shell(display);
    createContents(shell);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    display.dispose();
  }

  /**
   * Creates the main window's contents
   * 
   * @param shell the main window
   */
  private void createContents(Shell shell) {
    shell.setLayout(new FillLayout());
    StyledText styledText = new StyledText(shell, SWT.BORDER);

    // Add the line background listener
    styledText.addLineBackgroundListener(new LineBackgroundListener() {
      public void lineGetBackground(LineBackgroundEvent event) {
        if (event.lineText.indexOf("SWT") > -1) {
          event.lineBackground = red;
        }
      }
    });

  }

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








Related examples in the same category

1.ModifyEvent: Temperature Converter JFaceModifyEvent: Temperature Converter JFace
2.Mouse Event Listener Mouse Event Listener
3.Utility class for event handling
4.Demonstrates various listenersDemonstrates various listeners
5.Demonstrates mouse eventsDemonstrates mouse events
6.Demonstrates ControlListenersDemonstrates ControlListeners
7.SelectionListener and DisposeListenerSelectionListener and DisposeListener
8.Demonstrates FocusListenerDemonstrates FocusListener
9.Key Listener Example