0

I have a swing application and I want to copy some text to the system clipboard. I do this with

Clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
StringSelection dataToClipboard = new StringSelection(stringToCopy);
systemClipboard.setContents(dataToClipboard, null);

But it exists only inside the app, I can paste it in any text field in it, but when I try to do so in a web browser, it pastes nothing.

I also tried to implement ClipboardOwner interface and pass it's reference instead of null, but it didn't make a difference.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
joval
  • 466
  • 1
  • 6
  • 15
  • Does *"in a web browser"* mean 'applet'? – Andrew Thompson Oct 18 '12 at 08:44
  • @Andrew Thompson, no, it means a web browser (Chrome) – joval Oct 18 '12 at 08:49
  • Well what does the 'in a' mean? The only ways I know to 'put' Java 'in a' web browser are 1) applet & 2) servlet/JSP -- but the 2nd is a red herring, since what ends up in the browser is HTML (or similar). – Andrew Thompson Oct 18 '12 at 08:52
  • @Andrew Thompson raised as much as can be, the rest are unresolved problems – joval Oct 18 '12 at 13:30
  • 1
    @AndrewThompson: I understand "try to do so in a web browser" as meaning "try to paste the text i have copied in my application into a different application (for example, a text area in a web browser)". – Tom Anderson Oct 18 '12 at 14:40

2 Answers2

1

but when I try to do so in a web browser, it pastes nothing.

Digitally sign the app., or use the equivalent JNLP API Services in a sand-box.

See also this answer (and chase the links back to the thread at OTN) for more details.

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
0

Okay, I wrote the whole module again and this time it works.

Thank you for your time.

PS. By "in a web browser" I meant address bar in it;

joval
  • 466
  • 1
  • 6
  • 15