Results 1 to 2 of 2
Thread: Clipboard handling on Mac OS X
- 04-21-2012, 08:25 AM #1
Member
- Join Date
- Apr 2012
- Posts
- 2
- Rep Power
- 0
Clipboard handling on Mac OS X
Hi,
I'm having troubles getting data from the system clipboard on Mac OS X.
What I'm trying to do is to listen to the system clipboard and print the content of the clipboard each time new [text based] information is put into it.
The problem: bellow code works perfectly fine on Windows 7 and openSuse Linux machines, however when I try running the same code on Mac OS X the program fails to print the new content of the clipboard until focus is given to the application. [Nothing is printed until I click on the application icon on the dock...]
My source code:
Java Code:import java.awt.Toolkit; import java.awt.datatransfer.*; import java.io.IOException; public class ClipboardListener extends Thread implements ClipboardOwner { Clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); public void run(){ Transferable selection = systemClipboard.getContents(this); gainOwnership(selection); while (true) {} } public void gainOwnership(Transferable t){ try {this.sleep(100);} catch (InterruptedException e) {} systemClipboard.setContents(t, this); } public void lostOwnership(Clipboard clipboard, Transferable contents) { try {System.out.println((String) clipboard.getData(DataFlavor.stringFlavor));} catch (UnsupportedFlavorException e) {} catch (IOException e) {} gainOwnership(contents); } }I will appreciate any help, thanks!Java Code:public class myApp { public static void main(String[] args){ ClipboardListener listener = new ClipboardListener(); listener.start();} }Last edited by estro; 04-21-2012 at 10:05 AM.
- 04-21-2012, 02:32 PM #2
Member
- Join Date
- Apr 2012
- Posts
- 2
- Rep Power
- 0
Re: Clipboard handling on Mac OS X
It seems that the problem was identified: [#MACOSX_PORT-511] ClipboardOwner method lostClipboard is not called if app is not focused. - Java.net JIRA
Similar Threads
-
Clipboard on linux
By banhbaochay in forum New To JavaReplies: 1Last Post: 12-10-2010, 04:11 AM -
Clipboard and jTextPane
By Gudradain in forum AWT / SwingReplies: 11Last Post: 01-04-2009, 11:08 PM -
Copy from Clipboard in japplet
By AZMichael in forum Java AppletsReplies: 3Last Post: 09-06-2008, 02:30 PM -
SWT Clipboard Example
By Java Tip in forum SWTReplies: 0Last Post: 07-07-2008, 04:34 PM -
Using the clipboard
By Java Tip in forum java.awt.datatransferReplies: 0Last Post: 04-16-2008, 10:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks