Clipboard Composite : Clipboard « SWT JFace Eclipse « Java






Clipboard Composite

import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.RTFTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;

public class Ch12ClipboardComposite extends Composite {

  public Ch12ClipboardComposite(Composite parent) {
    super(parent, SWT.NONE);

    FillLayout layout = new FillLayout();
    setLayout(layout);

    Button b = new Button(this, SWT.NONE);
    b.setText("Copy to system clipboard");

    b.addSelectionListener(new SelectionListener() {

      public void widgetSelected(SelectionEvent e) {
        Clipboard clipboard = new Clipboard(getDisplay());
        String rtfData = "{\\rtf1\\b\\i Hello World}";
        RTFTransfer rtfTransfer = RTFTransfer.getInstance();
        clipboard.setContents(new Object[] { rtfData },
            new Transfer[] { rtfTransfer });
        clipboard.dispose();
      }

      public void widgetDefaultSelected(SelectionEvent e) {
      }

    });

  }
}

           
       








Related examples in the same category

1.Copy and PasteCopy and Paste
2.SWT Clipboard ExampleSWT Clipboard Example
3.Enable/disable menu depending on clipboard content availabilityEnable/disable menu depending on clipboard content availability
4.Copy and paste data with the clipboardCopy and paste data with the clipboard