jclipboardhelper
Helper library for dealing with the sytem's clipboard in Java.
Maven
You can use the following dependency in your pom.xml
:
<dependency>
<groupId>com.github.fracpete</groupId>
<artifactId>jclipboardhelper</artifactId>
<version>0.1.2</version>
</dependency>
Supported formats
-
Copy to clipboard
java.lang.String
java.awt.image.BufferedImage
javax.swing.JComponent
-- creates images from itjavax.swing.JTable
-- call the table's copy actionjava.awt.datatransfer.Transferable
-- supply your own implementation
-
Paste from clipboard
java.lang.String
java.awt.image.BufferedImage
java.awt.datatransfer.Transferable
-- returns just an Object
Example usage
Example code for copying data to the clipboard:
import java.awt.image.BufferedImage;
import com.github.fracpete.jclipboardhelper.ClipboardHelper;
...
ClipboardHelper.copyToClipboard("Hello World");
BufferedImage img = ...
ClipboardHelper.copyToClipboard(img);
Example code for obtaining data from the clipboard:
import java.awt.image.BufferedImage;
import com.github.fracpete.jclipboardhelper.ClipboardHelper;
...
if (ClipboardHelper.canPasteStringFromClipboard()) {
String s = ClipboardHelper.pasteStringFromClipboard();
}
if (ClipboardHelper.canPasteImageFromClipboard()) {
BufferedImage img = ClipboardHelper.pasteImageFromClipboard();
}
Example for clearing the clipboard:
import com.github.fracpete.jclipboardhelper.ClipboardHelper;
...
ClipboardHelper.clearClipboard();