Results 1 to 1 of 1
-
How to copy and paste data with the clipboard
Java Code:import org.eclipse.swt.SWT; import org.eclipse.swt.dnd.Clipboard; import org.eclipse.swt.dnd.TextTransfer; import org.eclipse.swt.dnd.Transfer; import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.layout.FormData; import org.eclipse.swt.layout.FormLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; public class Snippet94 { public static void main(String[] args) { Display display = new Display(); final Clipboard cb = new Clipboard(display); final Shell shell = new Shell(display); shell.setLayout(new FormLayout()); final Text text = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); Button copy = new Button(shell, SWT.PUSH); copy.setText("Copy"); copy.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { String textData = text.getSelectionText(); TextTransfer textTransfer = TextTransfer.getInstance(); cb.setContents(new Object[] { textData }, new Transfer[] { textTransfer }); } }); Button paste = new Button(shell, SWT.PUSH); paste.setText("Paste"); paste.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { TextTransfer transfer = TextTransfer.getInstance(); String data = (String) cb.getContents(transfer); if (data != null) { text.insert(data); } } }); FormData data = new FormData(); data.right = new FormAttachment(100, -5); data.top = new FormAttachment(0, 5); copy.setLayoutData(data); data = new FormData(); data.right = new FormAttachment(100, -5); data.top = new FormAttachment(copy, 5); paste.setLayoutData(data); data = new FormData(); data.left = new FormAttachment(0, 5); data.top = new FormAttachment(0, 5); data.right = new FormAttachment(copy, -5); data.bottom = new FormAttachment(100, -5); text.setLayoutData(data); shell.setSize(200, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } cb.dispose(); display.dispose(); } }"The sole cause of man’s unhappiness is that he does not know how to stay quietly in his room." - Blaise Pascal
Similar Threads
-
Requesting help in copy paste of folder similar to windows.
By selvin_raj in forum Advanced JavaReplies: 1Last Post: 06-23-2008, 06:46 AM -
Using the clipboard
By Java Tip in forum java.awt.datatransferReplies: 0Last Post: 04-16-2008, 10:52 PM -
Copy n' Paste in JEditorPane wraps text in new css..?
By Sam in forum AWT / SwingReplies: 0Last Post: 02-06-2008, 03:55 PM -
java copy paste cut and undo functions
By Mr tuition in forum AWT / SwingReplies: 1Last Post: 12-09-2007, 12:02 AM -
How to implement Cut and Paste
By Jamie in forum AWT / SwingReplies: 2Last Post: 05-31-2007, 06:15 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks