copy/paste through api

User ebc1e6aaea

15-04-2007 02:06:09

Is there a way to copy a molecule to the system clipboard through the JChem API? (As if right clicking on a MViewPane and choosing Edit>Copy)





Thanks

ChemAxon 7c2d26e5cf

16-04-2007 20:16:54

You can not access the copy action of Marvin from the JChem API but it is very easy to do it with the following custom code (if you need only a string copy):


Code:
import java.awt.datatransfer.*;


...


Molecule mol = viewPane.getM(0);


String s = mol.toFormat("mrv");


StringSelection selection = new StringSelection(s);


Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();


ClipboardOwner co = this;


clipboard.setContents(selection,(co);



(Your class has to implement java.awt.datatranfer.ClipboardOwner interface.)