![]() ![]() I tested this code last night, and it works as advertised, copying an Image (a BufferedImage in my case) to the Mac clipboard, after which I could then paste the image into other Mac applications. Toolkit, and the getSystemClipboard method. ![]() ![]() All I had to do was call the setClipboard method, and it handled the process of copying the image to the clipboard.Īs you can see from their source code, Java classes and interfaces you need to know about in this solution are: The actual solution to this problem comes from the excellent Example Depot website, specifically this clipboard example. Throw new UnsupportedFlavorException(flavor) Throws UnsupportedFlavorException, IOException Public Object getTransferData(DataFlavor flavor) Public boolean isDataFlavorSupported(DataFlavor flavor) Public DataFlavor getTransferDataFlavors() Static class ImageSelection implements Transferable This class is used to hold an image while on the clipboard. Toolkit.getDefaultToolkit().getSystemClipboard().setContents(imgSel, null) ImageSelection imgSel = new ImageSelection(image) Public static void setClipboard(Image image) This method writes a image to the system clipboard. Image image = activeMetaFrame.getCurrentImage() figure out which frame is in the foreground * Steps to take when the user requests the current image is copied to the clipboard. I won't discuss the solution here too much, other than to say that in the example source code below, a MetaFrame is a customized subclass of a JFrame, and when I call the getCurrentImage() function, it simply returns a Java Image type. Last night I needed to do just this, get an image that I'm currently displaying in a Java JFrame, and copy that image to the clipboard. Java Swing clipboard FAQ: How do I copy an image to the clipboard in a Java/Swing application? ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |