Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #30536
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Jeff Higgins <jeff@invalid.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: JEditorPane question |
| Date | Wed, 10 Dec 2014 00:46:08 -0500 |
| Organization | A noiseless patient Spider |
| Lines | 68 |
| Message-ID | <m68mof$f58$1@dont-email.me> (permalink) |
| References | <m64a5v$d3j$1@dont-email.me> <m659sr$5vl$1@dont-email.me> <m65car$d52$1@dont-email.me> <m65sr8$tdq$1@dont-email.me> <m68fdt$smd$1@dont-email.me> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Wed, 10 Dec 2014 05:46:55 +0000 (UTC) |
| Injection-Info | mx02.eternal-september.org; posting-host="c50a9e5d554cfaba13eda1c71e805135"; logging-data="15528"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/JoCNCdju6MzWzlHnhQjsbo9FvQ914feY=" |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.3.0 |
| In-Reply-To | <m68fdt$smd$1@dont-email.me> |
| Cancel-Lock | sha1:8Onv/Pqjj5Gr30lmn6s8vx6CDNE= |
| Xref | csiph.com comp.lang.java.programmer:30536 |
Show key headers only | View raw
On 12/09/2014 10:41 PM, Jeff Higgins wrote:
> Huh.
> Contents disappear from the system (OS)
> clipboard when I exit the application. :(
>
Damn.
SWT gets this simple thing right!
Close the Display and my selection is
still in the system clipboard.
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.RTFTransfer;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
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 bb {
public static void main(String[] args) {
Display display = new Display();
final Clipboard cb = new Clipboard(display);
Shell shell = new Shell(display);
final Text text = new Text(shell, SWT.BORDER | SWT.MULTI);
text.setBounds(10, 10, 300, 300);
Button button = new Button(shell, SWT.PUSH);
button.setText("Copy");
button.setBounds(320, 10, 100, 40);
button.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
String textData = text.getSelectionText();
if (textData == null)
return;
// to show the rtf formatting, make the text bold and italic
String rtfData = "{\\rtf1\\b\\i " + textData + "}";
TextTransfer textTransfer = TextTransfer.getInstance();
RTFTransfer rtfTransfer = RTFTransfer.getInstance();
Transfer[] types = new Transfer[] { textTransfer, rtfTransfer };
cb.setContents(new Object[] { textData, rtfData }, types);
}
});
button = new Button(shell, SWT.PUSH);
button.setText("Paste");
button.setBounds(320, 60, 100, 40);
button.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
TextTransfer transfer = TextTransfer.getInstance();
String data = (String) cb.getContents(transfer);
if (data == null)
return;
text.insert(data);
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
cb.dispose();
display.dispose();
}
}
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
JEditorPane question Martin Gregorie <martin@address-in-sig.invalid> - 2014-12-08 13:47 +0000
Re: JEditorPane question Jeff Higgins <jeff@invalid.invalid> - 2014-12-08 17:48 -0500
Re: JEditorPane question Martin Gregorie <martin@address-in-sig.invalid> - 2014-12-08 23:30 +0000
Re: JEditorPane question Jeff Higgins <jeff@invalid.invalid> - 2014-12-08 19:14 -0500
Re: JEditorPane question Jeff Higgins <jeff@invalid.invalid> - 2014-12-08 19:49 -0500
Re: JEditorPane question Jeff Higgins <jeff@invalid.invalid> - 2014-12-08 20:48 -0500
Re: JEditorPane question Jeff Higgins <jeff@invalid.invalid> - 2014-12-08 21:21 -0500
Re: JEditorPane question Jeff Higgins <jeff@invalid.invalid> - 2014-12-08 21:37 -0500
Re: JEditorPane question Jeff Higgins <jeff@invalid.invalid> - 2014-12-08 23:11 -0500
Re: JEditorPane question Jeff Higgins <jeff@invalid.invalid> - 2014-12-08 23:28 -0500
Re: JEditorPane question Martin Gregorie <martin@address-in-sig.invalid> - 2014-12-11 18:31 +0000
Re: JEditorPane question Martin Gregorie <martin@address-in-sig.invalid> - 2014-12-09 09:41 +0000
Re: JEditorPane question Jeff Higgins <jeff@invalid.invalid> - 2014-12-09 22:41 -0500
Re: JEditorPane question Jeff Higgins <jeff@invalid.invalid> - 2014-12-10 00:46 -0500
csiph-web