StyledText: addKeyListener(KeyListener key) : StyledText « org.eclipse.swt.custom « Java by API






StyledText: addKeyListener(KeyListener key)

import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.TextViewer;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class MainClass extends ApplicationWindow {
  public MainClass() {
    super(null);
  }

  public void run() {
    setBlockOnOpen(true);
    open();
    Display.getCurrent().dispose();
  }

  protected void configureShell(Shell shell) {
    super.configureShell(shell);
    shell.setText("Text Editor 2");
    shell.setSize(600, 400);
  }

  protected Control createContents(Composite parent) {
    TextViewer viewer = new TextViewer(parent, SWT.V_SCROLL);
    final StyledText styledText = viewer.getTextWidget();
    styledText.setWordWrap(true);
    styledText.addKeyListener(new KeyAdapter() {
      public void keyReleased(KeyEvent event) {
        if (event.keyCode == 'p' && (event.stateMask & SWT.CTRL) != 0) {
          styledText.print();
        }
      }
    });
    viewer.setDocument(new Document());
    return styledText;
  }

  public static void main(String[] args) {
    new MainClass().run();
  }
}

           
       








Related examples in the same category

1.StyledText: setWordWrap(boolean b)