How to clear the system clipboard in Java? -
how can clear system clipboard
in java? have tried
toolkit.getdefaulttoolkit().getsystemclipboard().setcontents(null, null);
but had thrown npe
:
exception in thread "awt-eventqueue-0" java.lang.nullpointerexception: contents @ sun.awt.datatransfer.sunclipboard.setcontents(sunclipboard.java:98)
you can create special transferable
explicitly contains no data, detailed in blog post:
clipboard.setcontents(new transferable() { public dataflavor[] gettransferdataflavors() { return new dataflavor[0]; } public boolean isdataflavorsupported(dataflavor flavor) { return false; } public object gettransferdata(dataflavor flavor) throws unsupportedflavorexception { throw new unsupportedflavorexception(flavor); }
Comments
Post a Comment