Listen to the Clipboard!

NetBeans allows you to listen to the Applications Clipboard. Here’s some example code that opens an IO-Window and prints a text representation of the clipboard content if available:

public class Installer extends ModuleInstall implements ClipboardListener{

@Override
 public void restored() {
 Lookup.getDefault().lookup(ExClipboard.class).addClipboardListener(this);
 }

@Override
 public void clipboardChanged(ClipboardEvent ev) {
 InputOutput io = IOProvider.getDefault().getIO ("ClipBoard History", true);

ExClipboard clipboard = ev.getClipboard();
 if(clipboard.isDataFlavorAvailable(DataFlavor.stringFlavor)){
 try {
 io.getOut().println("ClipBoard Content Changed:");
 io.getOut().println(""+clipboard.getData(DataFlavor.stringFlavor)+"");
 } catch (UnsupportedFlavorException ex) {
 Exceptions.printStackTrace(ex);
 } catch (IOException ex) {
 Exceptions.printStackTrace(ex);
 }
 }
 io.getOut().close();
 }
}

When the application is running, open “View”-> “IDE Log” and copy some text. Then the InputOuput should open and print the text. For the full project go to https://github.com/eppleton/netbeans-examples.

Enjoy and share the useful things you create with it!!

Dieser Eintrag wurde in netbeans geschrieben. Link merken.

Hinterlasse eine Antwort

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *

Du kannst folgende HTML-Tags benutzen: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>