Mega Code Archive

 
Categories / Java Tutorial / SWT
 

Using the Clipboard

import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class StyledTextClipboard {   public static void main(String[] args) {     final Display display = new Display();     final Shell shell = new Shell(display);     StyledText text1 = new StyledText(shell, SWT.V_SCROLL | SWT.WRAP | SWT.BORDER);     StyledText text2 = new StyledText(shell, SWT.V_SCROLL | SWT.WRAP | SWT.BORDER);     text1.setText("1234567");          text1.setSelectionRange(2,4);          text1.cut();     text2.paste();          text1.setBounds(10,10,100,100);          text2.setBounds(10,300,100,100);          shell.open();     while (!shell.isDisposed()) {       if (!display.readAndDispatch()) {         display.sleep();       }     }     display.dispose();   } }