Sending an image to the system clipboard

I've been trying to figure out how I can send an image to the system clipboard. At this state I'm beginning to think it's just not possible. This is the case:
I've got an applet running in a browser which creates a new window. I now want to copy the contents of this window to the system clipboard. So far I can only transfer text to the clipboard, but what I need is to copy a screenshot of the new window to the system clipboard.
Does anybody know how this can be done with Java or any kind of scripting language?

Since I already found the answer I rewarded 2 people for there help. This is the answer I found. Some code was found on the JDC Forum, but I can't remember who posted it or where I found it. So sorry that I can't give him credit...
Using JDK 1.4 the code could look like this:
-> This is how the policy file should look like:
grant
{ permission java.awt.AWTPermission "accessClipboard";
permission java.awt.AWTPermission "createRobot";
permission java.awt.AWTPermission "readDisplayPixels";
-> This is the code for the applet:
import java.awt.*;
public class ClipboardTest extends java.applet.Applet {
public void init() {
initComponents();
initialiseer();
private void initComponents() {
setLayout(new java.awt.BorderLayout());
public void initialiseer() {
     // Here I create the actual frame that I can send to the clipboard
MySystemClipboard cb = new MySystemClipboard();
cb.setBounds(200,200,200,200);
cb.setVisible(true);
-> And here is the code for MySystemClipboard:
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.datatransfer.*;
public class MySystemClipboard extends Frame implements ActionListener,
ClipboardOwner
private Button myButton;
private Clipboard myClipboard;
private PrettyPicture myPicture;
public MySystemClipboard()
add(myButton = new Button("Clip"), BorderLayout.SOUTH);
add(myPicture = new PrettyPicture(), BorderLayout.CENTER);
myButton.addActionListener(this);
myClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
public void actionPerformed(ActionEvent anEvent)
try
ClipImage ci = new ClipImage(new Robot().createScreenCapture(getBounds()));
myClipboard.setContents(ci, this);
catch (AWTException ae){}
public void lostOwnership(Clipboard clipboard, Transferable contents)
private class ClipImage implements Transferable
private DataFlavor[] myFlavors;
private BufferedImage myImage;
public ClipImage(BufferedImage theImage)
myFlavors = new DataFlavor[]{DataFlavor.imageFlavor};
myImage = theImage;
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException
if (flavor != DataFlavor.imageFlavor)
throw new UnsupportedFlavorException(flavor);
return myImage;
public DataFlavor[] getTransferDataFlavors()
return myFlavors;
public boolean isDataFlavorSupported(DataFlavor flavor)
return (flavor == DataFlavor.imageFlavor);
private class PrettyPicture extends Panel
public PrettyPicture()
setBackground(Color.gray);
add(new Button("Button1"), BorderLayout.NORTH);
add(new Button("Button2"), BorderLayout.CENTER);
add(new Button("Button3"), BorderLayout.SOUTH);
Hope this can help some other people

Similar Messages

  • Need to save the image saved in the System Clipboard in using JDK 1.3.1

    Does anyone know how to use JDK 1.3.1 to take an image saved in the System clipboard and save it to a file using the JPG format?
    I know how it is done in JDK 1.4 using the following code. Unfortunately, the same code does not recognize the image in the clipboard in JDK 1.3.1
    I am using jai-1_1_2_01.
    package clipboard;
    import java.awt.datatransfer.Clipboard;
    import java.awt.datatransfer.DataFlavor;
    import java.awt.datatransfer.Transferable;
    import java.awt.image.RenderedImage;
    import java.awt.Toolkit;
    import java.awt.datatransfer.UnsupportedFlavorException;
    import java.io.IOException;
    import java.io.FileOutputStream;
    import java.io.BufferedOutputStream;
    import java.io.File;
    import javax.media.jai.JAI;
    import javax.media.jai.RenderedOp;
    public class clipboard
    {  private File tempFile = null;
    * @param args
    static int BUFFER_SIZE = 65536;
    public static void main(String[] args)
    {  clipboard clip = new clipboard();
    clip.writeImageFromClipboard();
    public void writeImageFromClipboard()
    {  Clipboard            clip = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable transferable = clip.getContents(null);
    RenderedImage img = null;
    FileOutputStream fileOutStr = null;
    BufferedOutputStream bufOutStr = null;
    DataFlavor [] dataFlavors;
    File tempFile;
    int
    byteCount;
    String [] strArr;
    dataFlavors = transferable.getTransferDataFlavors();
    System.out.println("clip=" + clip.getName());
    System.out.println("Transferable=" + transferable);
    for (int i = 0; i < dataFlavors.length; i++)
    {  System.out.println("dataFlavours[" + i + "]=" + dataFlavors.toString());
    if (transferable.isDataFlavorSupported(new DataFlavor("image/x-java-image; class=java.awt.Image", "Image")))
    { try
    { img = (RenderedImage) transferable.getTransferData(new DataFlavor("image/x-java-image; class=java.awt.Image", "Image"));
    if (this.tempFile == null)
    { this.tempFile = File.createTempFile("__TMP_IMG__", ".jpg");
    System.out.println(this.tempFile.getCanonicalPath());
    fileOutStr = new FileOutputStream(this.tempFile);
    bufOutStr = new BufferedOutputStream(fileOutStr);
    // Encode the file as a JPG image.
    JAI.create("encode", img, bufOutStr, "JPEG", null);
    catch (UnsupportedFlavorException e)
    { e.printStackTrace();
    catch (IOException e)
    { e.printStackTrace();
    finally
    { if (bufOutStr != null)
    { try
    { bufOutStr.flush();
    bufOutStr.close();
    catch (IOException e)
    if (fileOutStr != null)
    { try
    { fileOutStr.flush();
    fileOutStr.close();
    catch (IOException e)
    else
    { System.out.println("Not an image!");

    The login  you connected to the server  and run the above statement does not have permissions to operate  on this path "C:\Users\ISLLCdba\Desktop\MAA
    PROFILE PICTURES\"
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Writing to the System clipboard

    This company uses LabVIEW 2012 and LabWindows 2010 in an Aerospace environment. The use of older versions is done to have commonality with their facilities across the globe. Thus, I cannot get them to upgrade.
    On their new test station, they have 14 serial ports to communicate with the unit under test. I have developed a LabVIEW serial port interface program that will allow them to communicate with those serial ports. I have the ini file configured to allow the user to run multiple instances of the executable, for as many ports as they desire, during their testing. One option that they requested is the ability to right click the mouse, have a menu display to select copy or copy all of the data to the clipboard so that they can paste the received data into a test report. I used the LabVIEW App Invoke Node function Write to Clipboard and Read From Clipboard to perform the task. However, I have the issue that this works on some instances and does not work on other instances of the executables. Since the code is the same, the user enters which port to connect to, I do not understand why I have this issue. It works fine on my PC which only has a single COM port.
    I decided to write two LabWindows functions to read and write to the clipboard using ClipboardGetText and ClipboardPutText. I call those dll functions from LabVIEW. The first call to the function ClipboardPutText works in the sense that the data is placed into the clipboard. However, I immediately get a fatal error and the process stops. (I did not save a screen image and the test stations are in use at this time). After that, none of the other instances will copy the data and they all result in a fatal error and stop. This is repeatable as I restarted the software numerous times as I tried to determine the cause.
    Since I do not have access to the code for the clipboard functions, I cannot determine if I need to configure something else related to the clipboard or the process attempting to read/write from/to the clipboard. I will continue to search but wanted to ask the experts in control of the clipboard software to determine if they have any recommendations on what may need to be added.
    For LabWindows, the only other call that I performed was a free command after I executed the ClipboardGetText, if the pointer to the text was not NULL.
    I will post this in both the LabVIEW and LabWindows discussion boards in case one or the other has a solution.
    Thank you for your help.
    I can provide a zip file, containing the source code, to NI personnel if you provide an email address. Since I am a contractor, I am not sure if the company’s policy allows global posting of their code, although I may be able to reduce the code to a minimum example, if necessary.

    I have done more testing in an attempt to clarify the error condition. I upgraded to LabVIEW 2014 on a Windows 7 SP1 system. I have enclosed some screen shots to show what I am doing.
    My software allows multiple copies, 14 in this case, versions of the executable to run at one time. The software controls serial ports. The enclosed image of the front panel, LabVIEW window.png, indicates the COM port, baud rate, and version at the top of the window. This first small control allows the user to enter a command to send to the port. The large bottom indicator displays the data received on the port. I have menu items, pressing the right mouse button, that allows the user to clear all of the data, copy selected data, or copy all data. I have enclosed images of the copy, copy all, write to clipboard, and read serial port parts of the code. I was only copying small amounts of data, perhaps less than 256 bytes.
    Here’s what I have noticed:
    If I execute the code on my desktop computer, only 1 COM port, everything works fine. The copy and copy all will place the data into the system clipboard which allows the pasting of the data into Notepad.
    If I execute the code on the test station, opening all 14 ports, we are using the NI serial card for all of the additional ports, the code works fine, as in item 1, for a couple of the executables but not the rest.
    If I select a subset of the data being displayed, highlighted in blue by LabVIEW, then right click the mouse selecting the copy, the blue highlighting goes away but the data is copied to the clipboard allowing me to paste into Notepad.
    If I right click the mouse selecting copy all, the data is NOT copied to the system clipboard so that I cannot paste it into Notepad.
    In the Write to Clipboard function, I write to the clipboard and then read the clipboard. I added code to display, in a popup window, what was written to the clipboard and what was read from the clipboard. The data was the same although the data was not on the system clipboard so that I could paste it into Notepad.
    I tried to select a subset of the data being displayed and then right clicking the mouse to do a copy all to see if that made a difference. It did not.
    I tried to make the Write to Clipboard function re-entrant to test that theory. Not change in the behavior.
    At one point, I tried to use LabWindows. I used the LabWindows clipboard calls and then tried calling the Microsoft clipboard functions directly. While those functions worked in LabWindows without a problem, I would get executable crashes when I tried to call my LabWindows functions from LabVIEW. If I commented out the actually code part, the call to the functions would return without crashing the executable. The issue was not in how the LabWindows functions were being called but something in the clipboard calls themselves. So, I decided that making a call using LabWindows offered nothing that I could use. I returned to using only LabVIEW and updated to 2014 to determine if that might solve the issue. No luck so far.I do not understand why, when I call the LabVIEW function to write to the clipboard, that it does not work for every executable of the multiple instances. Is there some other function that needs to be called prior to writing to the clipboard due to having multiple instances? Why does selecting a subset work when I do the copy but not when I copy all. If I am passing the data to write to the clipboard, why does selecting a subset and the copying only that subset work but the copy all does not? I do not understand how LabVIEW handles multiple instances and is they are truly considered separate processes.
    I seldom use these forums as I can get most of the code that I write to work as expected. Thank you for all of your help and suggestions.
    Attachments:
    LabVIEW window.png ‏25 KB
    Copy Menu Item.png ‏39 KB
    Copy ALL Menu Item.png ‏33 KB

  • In the new Pages, how does one send an image to the background (and make it selectable)?

    How does one send an image to the background in the new Pages and how does one make it selectable?

    Also why don't TEXT to Speech short cuts established in system preferences work in the new Pages?
    I am confused (and not completely happy)

  • Copying to the system clipboard

    Hi...
    I am trying to copy the contents of a JPanel to the system clipboard so I can paste it into an app like MS Word. The JPanel just has some lines and dots on it that I've drawn with draw and fillOval.
    I am VERY new to Java so the only way I could figure out to do this was to save the contents of the panel as a .jpg and then wrap it up in a class I created that implements the transferrable interface. This works....and I can paste it into Word and it looks fine on the screen. But when I print it.....it looks very grainy. So I'd like to be able to copy this panel to the clipboard in some other way besides saving it as an image first.
    Is there any other direct way to copy components like a panel with shapes drawn on it to the system clipboard that anyone knows of?
    Thanks in advance!
    Julie

    Thanks for the suggestion. I tried it...but it still looks like crap when I print it.
    I am drawing directly on a Graphics2D object (the exact size I want), then I put into a BufferedImage. Then I save the BufferedImage as a .png, open it back up and copy it to the system clipboard.
    It is just the image quality. Is there a way to manipulate the DPI?
    Thanks again,
    Julie

  • M30X-124: Power Saver image in the system tray disappeares.

    Hi,
    I own a Satellite M30X-124 with Windows XP SP2. When installing Toshiba Power Saver everything works just until suddently the image in the system tray disappeares. I then have to reinstall the Toshiba Power Saver (TPS) for everything to work as intended.
    By now, I have approx. reinstalled TPS 5 times. Does anyone know a solution or at least the problem?
    Greetz,
    Micha

    Hello
    Well, I think its not a Power Saver malfunction. I assume that the option Hide inactive icons in the Taskbar and Start Menu Properties is marked.
    Move the mouse pointer to the Taskbar then right click. There you should see the Taskbar properties. There you can disable the option Hide inactive icons.
    Bye

  • Issue with sending an image in the body of email using SAP ABAP

    Hello All,
    We have a requirement to send an email to our external clients that contains an image in the body of the email. We are using cl_bcs class in ABAP to send the email and the mail is sending in html format.
    We have uploaded the image in the SAP system using the transaction u2018SMW0u2019 and we are using the Function Module 'WWW_GET_MIME_OBJECT' to retrieve the image while sending the mail. But image is not displayed in the mail by using this approach.
    When we tried to use the image URL from the company website with <img> tag of the html code in the ABAP Program, the image is displayed in the mail. But, to display the image we need to use the download option and also it is taking time to download.
    Our aim is to download the image automatically in the mail. I have searched sdn but couldn't find complete info.
    If anyone worked on the similar functionality, kindly reply.
    Thanks in advance for your help.
    Best Regards,
    Ravi.

    Are you trying to send the e-mail with the image embedded? I did it with PHP and Phython... Never done it in ABAP, sadly to say... but I guess it should be possible. You'll need to play with the way the HTML code of the e-mail is being created, using MIME and the right headers. I'm guessing the result of WWW_GET_MIME_OBJECT will be your 'Content-ID'.
    Do some google with "Send an HTML email with embedded image". Even if it's related to another programming language it might give you some clues about how to compose the e-mail and you'll be able to replicate the logic by using CL_BCS.
    An alternative would be to just attach the image to the e-mail.
    Cheers,
    Andres.

  • Outlook 2010 - sending mail with attachment - "The system cannot find the file specified"

    Hi forum Fellows,
    I have the following failure scenario:
    1. A user receives an e-mail with an attachment.
    2. The user opens the attachment --> Forwards the mail and writes something in the body of the e-mail
    3. For whatever reason the user leaves the e-mail and works on something else --> the user comes back to the e-mail an hour or more later.
    4. The user then wants to send the e-mail but gets the following error message: "The system cannot find the file specified"
    5. The effect is that the user cannot send the e-mail.....
    ------------------------------ TROUBLESHOOTING -----------------------
    - I can see that when the user opens an attachment this attachment is saved in the OutlookTemp folder. Actually, there is a difference between opening the attachment before or after clicking forward on the e-mail.
    ---- Before: Two files is written to the OutlookTemp folder. For example if the attachment name is FileX.pdf - there will be a FileX.pdf but also a FileX (2).pdf in the folder (if OutlookTemp is empty/do not contain a file with the name FileX.pdf already)
    ---- After: Only one file is written to OutlookTemp. That is FileX.pdf
    - Running Process Monitor when trying to forward the e-mail I can see that Outlook is calling a file that is not in the OutlookTemp folder anymore.
    **** To me this is the heart of the issue. For some reason, when a user has an e-mail with an attachment open for an extended period of time (not sure on exactly how long is necessary), files in the OutlookTemp folder is deleted - files that Outlook is depending
    on to be there.
    - Going with a totally clean OutlookTemp folder does not help.
    ------------------ NOW WHAT ---------------
    - The question now is: Is this by design? Can it be fixed by some Outlook 2010 patch? Or perhaps a group policy/registry setting as a workaround.
    ------------------------------ TECH. INFO -----------------------
    Outlook 2010 v14.0.7132.5000
    Outlook bit depth: x86
    Running on a 2008R2 SP1 TS environment.
    No antivirus on the TS
    Looking forward to hear from you.
    Regards The Red Baron
    Red Baron

    Hello Red Baron,
    Although not a complete answer, the way to treat attachments in emails require some discipline:
    1. Never open an attachment directly from the email (and NEVER edit it from there). Always save it in a known location as the desktop or (better) in a designated document folder. Then you can proceed as usual, like editing the contents, printing, forwarding
    the new version etc.
    2. Directly forwarding the attachment is ok, along with additional text in the body of the email.
    3. Having any (unsaved) document open for several hours should
    never occur. What if there is a power outage?
    Bottom line is thus Discipline. This is regardless of Operating System (which might handle temporary files differently).
    These are the rules I teach my customers and they never leave any document unsaved for hours ...
    Best regards George

  • I have a big mail problem. I foolishly tried to send a video photo by email.  Not surprisingly, it was taking a very great deal of time so I eventually deleted the 'send'. But, now the system keeps copying the deleted email and attachment

    My email program has got itself gummed up due t my foolishly trying to send a video attachment. I eventually 'stopped' the 'send' but the system has brought in a 'Recovered files' heading and has retained the email complete with video attachment and keeps copying the darned thing. I keep deleting but it still comtinues copying. Once there were 45 copies. Please can someone tell me how to get rid of the files.

    The idea to jumpstart by change was not the smartest one, but gives you an opportunity to use that "temporary" account as permanent. You do not have a choice cause obviously despite you thinking that old account is no more -it does exist on Apple servers. And if you are unwilling to share your [email protected] with friend, just create one extra [email protected] for your friend. One suggestion - do not use gmail.

  • How cacn I clear the system clipboard content? and notify

    Hi all,
    I have any question please,
    -How can I clear the content of system clipboard?
    -How can I notify if a paste failed, the application which start the cut, so not remove the elements which selected for cut? /Cut & paste between two applications/
    Thx.

    Hi,
    try to search the forum as I did:
    http://onesearch.sun.com/search/onesearch/index.jsp?charset=utf-8&qt=how+to+use+clipboard&rf=0&rt=1&nh=10&cs=0&y=0&x=0&col=developer-forums
    L.P.

  • I cannot send dng images with the Adobe emailer?

    I am unable to send my dng images as email attachments using the Adobe emailer.  I get a message telling me that dng images cannot be converted?  What do I need to do to send them using the Adobe email?
    Thank you.
    Dwight

    You need to contact your ISP and find out what you need to use as your out going email server SMTP Server is.  Is should be the same as the one you use on your email on your PC (Windoze or Mac). if you are using gMail they have a guide for setting up your email on a email client.

  • Send control image programmat​ically to clipboard

    Hi all
    The right click option allows one to copy or export simplified image to clipboard.
    Programmatically, "export simplified image "is not possible.
    Using "invoke node", it is posible to save in a file as jpg/bmp/pmg.
    Does somebody has a vi to copy graph control image programmatically to clipboard as jpg or emf?
    thanks
    Alipio
    "Qod natura non dat, Salmantica non praestat"

    Hello,
    I have needed to programmatically copy image data to the clipboard too. In the past I have used George's toolset. However with Labview 8.5, you can do it. Attached is a snippet that shows how you can use the picture methods to export to either the clipboard or a file. Can't do it in either LV8, or LV8.2. Sad.
    Attachments:
    copy to clipboard test.vi ‏35 KB

  • .nomedia not working album showing every single image in the system

    there are same questions like this in this forum, I did my search but none of them has a solution.
    And this problem is annoying me. I see every single image present in my cell phone in the album app.
    from frames and stickers of a photo editor to the album arts of music files and profile images and what not.
    I was using another app to view images but i have to admit the default album app is better, but why doesn't it 
    recognize .nomedia files and go on displaying every image. 
    is there any solution to this. hope they fix this in the next update. sony are you listening.
    Solved!
    Go to Solution.

    I am using "quickpic" now. came across the name in this forum itself for the same problem.Thanks to that guy.
    quickpic does my job. it is less than 1Mb and performs better than the sony album app. it is fast, organized, elegant even plays videos what else can i ask for.

  • How to returm data in the form of InputStream to the System Clipboard ?

    Hi All,
    I wanted to transfer some data to the clipboard from the file using InputStream. How can I do that ? How to close the InputStream after datatransfer finished ? Some code would be great help.......
    Thanks,
    Sid

    Hello,
    I think the easiest way is to just define a table with line type of a long charachter field e.g. chart255 or string. Then get the lines by splitting the string into a table then loop about the table.
    DATA:
      lv_string TYPE                   string,
      lv_line   TYPE                   string,
      lt_lines  TYPE STANDARD TABLE OF string.
    lv_string = 'line1##line2##line3##line4'.
    SPLIT lv_string AT '##' INTO TABLE lt_lines.
    LOOP AT lt_lines INTO lv_line.
      WRITE / lv_line.
    ENDLOOP.
    Best Regards
    Roman

  • Paste Image to System Clipboard

    Hello all...I can't paste an Image to the system clipboard and was wondering if you could help me. Noticed there was some help on this topic with JDK 1.4.1, however I'm using JDK 1.3.1.
    I following code was copied from Sun at http://developer.java.sun.com/developer/Books/GJ21AWT/ch20.pdf
    but I cant get it to work.
    <code>
    //implement the class like this
    ImageSelection is = new ImageSelection(Constants.DRAWINGSLATE.currentImage.pBitmap[dList.ptr].getImage());
    toolkit.getSystemClipboard().setContents(is, null);
    class ImageSelection implements ClipboardOwner, Transferable
    public static DataFlavor ImageFlavor;
    public static DataFlavor ImageArrayFlavor;
    private DataFlavor[] flavors = {ImageFlavor, ImageArrayFlavor};
    private java.awt.Image image;
    private int width, height;
    static
    try
    ImageFlavor = new DataFlavor(Class.forName("java.awt.Image"),"AWT Image");
    ImageArrayFlavor = new DataFlavor("image/gif", "GIF Image");
    catch(Exception e)
    public ImageSelection(Image image)
    this.image = image;
    public ImageSelection(Image image, int width, int height)
    this.image = image;
    this.width = width;
    this.height = height;
    public synchronized DataFlavor[] getTransferDataFlavors()
    return flavors;
    public boolean isDataFlavorSupported(DataFlavor flavor)
    return flavor.equals(ImageFlavor) || flavor.equals(ImageArrayFlavor);
    public synchronized Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException
    if (flavor.equals(ImageFlavor))
    return image;
    if (flavor.equals(ImageArrayFlavor))
    return imageToArray();
    else
    throw new UnsupportedFlavorException(flavor);
    public void lostOwnership(Clipboard c, Transferable t)
    private int[] imageToArray()
    int[] pixels = new int[width*height];
    PixelGrabber pg = new PixelGrabber(image, 0, 0, width, height, pixels, 0 , width);
    try
    pg.grabPixels();
    catch(InterruptedException e)
    e.printStackTrace();
    return pixels;
    </code>
    I get this exception
    Couldn't write data flavor java.awt.datatransfer.DataFlavor[representationclass=java.awt.Image;mimetype=application/x-java-serialized-object] to clipboard:
    java.io.IOException: Transferable's flavor data is of unexpected class com.apple.mrj.internal.awt.graphics.VImage
    Thanks for any help.

    I was trying to use ur code with slight modification
    import java.awt.*;
    import java.awt.datatransfer.*;
    import java.io.*;
    import java.util.*;
    public class Test {
    public static void main (String[] parameters) {
              new Test ().test ();
    private void test () {
    Toolkit.getDefaultToolkit().getSystemClipboard ().setContents (          new mageTransferable ("test.jpg"),
         new ClipboardOwner () {
         public void lostOwnership (                                             Clipboard clipboard,
                             Transferable contents) {}
    private class ImageTransferable implements Transferable {
    private String fileName;
    public ImageTransferable (String fileName) {
    System.out.println(" Checking for the File now");
    if (! new File(fileName).exists ()) {
    throw new IllegalArgumentException ("Can't find image");
    System.out.println(" got the file");
    this.fileName = fileName;
    System.out.println(" returning from constructor");
    public Object getTransferData (DataFlavor flavor) throws UnsupportedFlavorException {
    System.out.println("trying to get the data to be transfered");
    if (! isDataFlavorSupported (flavor)) {
    throw new UnsupportedFlavorException (flavor);
    System.out.println("This is a supported flavor");
    return (Image)Toolkit.getDefaultToolkit().createImage (fileName);
    //               System.out.println(
    public boolean isDataFlavorSupported (DataFlavor flavor) {
    System.out.println("trying to check whether the flavour is supported one");
    DataFlavor[] df= this.getTransferDataFlavors();
    System.out.println(" data flavors " + df);
    boolean result = in(flavor, df);
    return result;
    public DataFlavor[] getTransferDataFlavors () {
    //     "image/x-java-image; class=java.awt.Image"
    DataFlavor df=null;
    System.out.println("trying to get the data flavours");
    df =new DataFlavor("application/x-java-serialized-object; class=java.awt.Image","Image");
    //new DataFlavor("image/x-java-image;class=java.awt.Image","Image");
    System.out.println(" Just going to return & DF found was"+ df);
    DataFlavor[] df2 = new DataFlavor[]{df,DataFlavor.plainTextFlavor,DataFlavor.stringFlavor,DataFlavor.javaFileListFlavor };
    System.out.println(df2.length);
    System.out.println(df2[0]);
    return df2;
    private boolean in (DataFlavor flavor, DataFlavor[] flavors) {
    System.out.println("Im in in");
    int f = 0;
    while ((f < flavors.length) && ! flavor.equals (flavors[f])) {
         f ++;
         System.out.println("Im in in's loop");
    return f < flavors.length;
    But this throws the following exception:
    Exception in thread "main" java.lang.ClassCastException: sun.awt.windows.WImage
    at sun.awt.windows.WDataTransferer.translateTransferable(WDataTransferer
    .java:346)
    at sun.awt.DataTransferer.translateTransferable(DataTransferer.java:245)
    at sun.awt.windows.WClipboard.setContents(WClipboard.java:69)
    at Test.test(Test.java:13)
    at Test.main(Test.java:8)
    Is the dataflavour purely dependent on OS. What can be done to overcome this problem

Maybe you are looking for