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

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

  • 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

  • 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

  • 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.

  • Writing to the System root in UNIX

    My Application creates charts and puts it in a root directory of the System.How to use java api to read it back in and display the Image since the directory where the charts are being generated is outside the
    Root Context of the Application. For e.g the generated charts are within
    /tmp/charts/ if i write ../../../tmp/charts or /tmp/charts the image within the directory doesnt gets displayed on the web page.
    Thanks in Advance

    Thanks !! but i think u didnt get my problem.In the UNIX machine i have an jpg image File at the System Root directory called /tmp/charts.
    In the same Machine there is weblogic Server which hosts my application.In my Application i need to display that Image stored at the Root. How to access the /tmp/charts directory from the Root-Context
    of my Application..If i do like <img src="../../tmp/charts/sth.jpg" it doesnt displays the Image unlike in Windows.What should i write in the img src to display that Image.

  • 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

  • Writing on system clipboard from an applet.

    Is it possible?
    I have tried to write on it but an exception is occoured:
    java.security.AccessControlException: access denied (java.awt.AWTPermission accessClipboard)
    The code that I have used is:
    import java.security.*;
    import java.awt.*;
    import java.awt.datatransfer.*;
    import javax.swing.*;
    public class Blah extends JApplet {
    public void init() {
    String exampleStr = "Hi!";
    Clipboard clipboard;
    Transferable trans;
    StringSelection strSelect;
    try {
    SecurityManager security = System.getSecurityManager();
    if (security != null)
    security.checkSystemClipboardAccess();
    clipboard=Toolkit.getDefaultToolkit().getSystemClipboard();
    strSelect = new StringSelection(exampleStr);
    trans = (Transferable)strSelect;
    clipboard.setContents(trans, strSelect);
    System.out.println("Clipboard copy successful");
    catch (Exception e) {
    System.err.println("Clipboard copy failed");
    System.err.println(e);
    Thanks

    First, your applet must be signed to access the system clipboard. And on Netscape 4.7.x, you need to enable the privilege from within the same method where you get the system clipboard. On IE 5.5/6.0, signing the applet is all that is necessary.
    Here's what I do on Netscape:
    Make sure when you call "PrivilegeManager.enablePrivilege("UniversalSystemClipboardAccess");", that you get the system clipboard within the same method. Failure to do this will cause a ForbiddenTargetException.
    My code looks like:
    public java.awt.datatransfer.Clipboard getSystemClipboard()
    java.awt.datatransfer.Clipboard clipboard = null;
    try
    PrivilegeManager.enablePrivilege("UniversalSystemClipboardAccess");
    clipboard = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
    PrivilegeManager.revertPrivilege("UniversalSystemClipboardAccess");
    catch (netscape.security.ForbiddenTargetException se)
    se.printStackTrace();
    catch(Exception e)
    e.printStackTrace();
    return clipboard;
    This works successfully on Netscape 4.7.8. On IE 5.5/6.0, I didn't have to do anything other than having a signed applet to get the system clipboard. With the code above, I also am using a signed applet.
    Hope this helps anyone else trying to make this work.
    -Dave.

  • Problems copying from PJC to system clipboard

    I am working on a PJC to allow for editing of large text fields (> 64K). I have most of the functionality working fine. However, I am having a problem using cut, copy, and paste.
    Some details, the PJC extends VBean and includes as JTextArea. Our users want a right click menu to provide functionality for cutting, copying, pasting, and spell checking. I was able to get the spell check working using JSpell. I am not able to get the menu entries for cut, copy, and paste to work. I construct a JPopMenu with the appropriate items. When the menu is activated, if the user selects cut, the actionPerformed method executed the cut method of the JTextArea. This does cut the text from the item, however it is not added to the clipboard for use in other items, except those that have the same implementation class of the original item. If the user uses the keyboard (CTRL-X, CTRL-C, or CTRL-V) the selected data is copied to the system clipboard
    Here is the method I used to create the menu items:
      private JMenuItem makeMenuItem(String label, char acceleratorKey)
        JMenuItem item = new JMenuItem(label);
        item.addActionListener(this);
        item.setMnemonic(acceleratorKey);
        item.addKeyListener(this);
        printDebugMessage("Horizontal text alignment = " + item.getHorizontalAlignment());
        item.setHorizontalAlignment(SwingConstants.LEFT);
        printDebugMessage("Horizontal text alignment = " + item.getHorizontalAlignment());
        return item;
      }Here is the actionPerformed method:
      public void actionPerformed(ActionEvent ae)
        String selection = ae.getActionCommand();
        if (selection.equals("Cut"))
          printDebugMessage("Cut selected");
          text.cut();
        else if (selection.equals("Copy"))
          printDebugMessage("Copy selected");
          text.copy();
        else if (selection.equals("Paste"))
          printDebugMessage("Paste selected");
          text.paste();
        else if (selection.equals("Spell Check"))
          printDebugMessage("Spell Check selected");
          doSpellCheck();
      }I read that jar files needed to be signed to interact with the desktop, but when I signed the jar file the results were the same.
    Platform
    10g AS on Solaris 10.1.2.2
    Windows XP (SP2)
    IE7
    Sun plugin 1.5.0_11 (problem also occurs with 1.4.2_06)
    Any insights would be helpful.
    Thanks

    will that create a problem?Try it and see.

  • Signed Applet JTextField copy to system clipboard

    Hi all,
    We have a signed and deployed our JAR file that contains our applet following the instructions listed at:
    http://java.sun.com/products/plugin/1.3/docs/rsa_signing.html
    We used Thwate as our CA. All seemed good.
    However any JTextFields that are in our applet cannot access the system clip board. Looking at the source for JTextComponent it should have access to the system clipboard if the securitymanager allows it.
    The strange thing is that if I call getToolkit().getSystemClipboard() from our applets I can access the clipboard and copy to the system clipboard. Even the code in JTextComponent that checks for system clipboard access (canAccessSystemClipboard) works fine when pasted into the applet.
    Why cant a JTextField copy to the clipboard? Has anyone else come across this?

    Juste an idea.... Is your JTextField belonging to the javax.swing.... packages ?
    Or did you compile using some com.ms , ibm.... sun... package ? This could lead to some different implementations.

  • 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

  • Applet access to system Clipboard

    Hi all:
    I am creating a customized version of the mud telnet application for a customer. They have requested cut/paste functionality and I have been able to provide this capability. The problem is the applet cannot get access to the system clipboard so all cut/paste functions can only occur within the applet. I am able to access the system clipboard by creating a java.policy file and setting a permission. The problem is that most of the workstations, and a good number that will be using home computers running Win 98. They don't want the users to have to download the new JRE from Sun (although I know this works). I am looking for a way to creat a JAR file using the old JDK 1.1 (or the current toolkit if it is possible) that will allow access from the Applet to the System Clipboard. I have search the web for an answer, with no success. Can anyone give me any suggestions?
    Anybody had to do the same thing before?
    Thanks.
    John Kreiner

    I know this is an old thread, but I thought I would answer it.
    To access the clipboard via an applet, you need to use JavaScript.
    The first thing to do is to create a class that uses reflection to use the JSObject. The reason why reflection is used is because it is a pain (ITA) to specify a compatible binary for eacy java version (e.g. java40.jar, plugin.jar, jaws.jar, etc). Here is the class:
    import java.lang.reflect.*;
    import java.applet.Applet;
    public class JavaScript {
         public static void call(Applet applet, String methodName, Object[] param) {
              try {
                   Class js = Class.forName("netscape.javascript.JSObject");
                   Method callMethod = js.getMethod("call", new Class[] { String.class, Object[].class });
                   callMethod.invoke(getWindow(applet), new Object[] { methodName, param});
              } catch (Throwable t) {}
         public static Object getWindow(Applet applet) {
              Object o = null;
              try {
                   Class js = Class.forName("netscape.javascript.JSObject");
                   Method getWindowMethod = js.getMethod("getWindow", new Class[] { Applet.class });
                   o = getWindowMethod.invoke(null, new Object[] { applet });
              } catch (Throwable t) {}
              return o;
    }Now, when you want to copy something to the clipboard, you will do:
    JavaScript.call(someApplet, "copyToClipboard", text);
    BUT the "copyToClipboard" function has not been defined yet. This will be a JavaScript function in the html:
    <script language="JavaScript1.1">
    function copyToClipboard(text) {
         document.myForm.myInput.value = text;
         var rng = document.myForm.myInput.createTextRange();
         rng.execCommand("RemoveFormat");
         rng.execCommand("Copy");
    </script>And one last thing is that a JavaScript text component is required in order to create the "rng" variable. To do this, use a hidden field in the html:
    <form name="myForm">
         <input name="myInput" type="hidden">
         </input>
    </form>

  • Programatically copy to  System Clipboard

    I'm trying to programatically copy a value from my applet to the system clipboard without much luck. My jars have all been signed and I am able to ctrl-c and ctrl-v to/from the applet/system clipboard. What I need to be able to do is invoke this behaviour from a popup menu. Below is a code snippet:
    public void actionPerformed(ActionEvent event)
                   Object source  = event.getSource();
                   String strValue = source.toString();
                   StringSelection strSelection = new StringSelection(strValue);
                   Toolkit.getDefaultToolkit().getSystemClipboard().setContents( strSelection , strSelection );
                    // at this point I have verified that 't' does indeed contain my item.
                   Transferable t =Toolkit.getDefaultToolkit().getSystemClipboard().getContents(strSelection );
    }When I try to paste into, say notepad, there does not appear to be anything in the clipboard.
    Any idea as to what I'm doing wrong? I'm using 1.5 plugin (but want to move down to 1.4)
    Thanks,
    -Craig Green

    I guess you didn't sign it right or called your method from untrusted (unsigned) code.
    for signing:
    http://forum.java.sun.com/thread.jsp?forum=63&thread=524815
    second post
    for a full trace:
    To turn the full trace on (windows) you can start the java console, to be found here:
    C:\Program Files\Java\j2re1.4...\bin\jpicpl32.exe
    In the advanced tab you can fill in something for runtime parameters fill in this:
    -Djavaplugin.trace=true -Djavaplugin.trace.option=basic|net|security|ext|liveconnect
    if you cannot start the java console check here:
    C:\Documents and Settings\userName\Application Data\Sun\Java\Deployment\deployment.properties
    I think for linux this is somewhere in youruserdir/java (hidden directory)
    add or change the following line:
    javaplugin.jre.params=-Djavaplugin.trace\=true -Djavaplugin.trace.option\=basic|net|security|ext|liveconnect
    for 1.5:
    deployment.javapi.jre.1.5.0.args=-Djavaplugin.trace\=true -Djavaplugin.trace.option\=basic|net|security|ext|liveconnect
    The trace is here:
    C:\Documents and Settings\your user\Application Data\Sun\Java\Deployment\log\plugin...log
    I think for linux this is somewhere in youruserdir/java (hidden directory)

  • Copying to system clipboard

    i m tryin to copy an image to the system clipboard,. the syntax being the usual
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selectedImage,null);
    i m not invoking the method      javax.swing.SwingUtilities.invokeLater(new Runnable(){
              public void run()
    will that create a problem? cuz i can run it normally wen i m not

    will that create a problem?Try it and see.

  • System clipboard pasting multi lines

    I have a small java snippet that will copy text to the system clipboard. what i need to know is how to make it copy more than one single string to the system clipboard? Any ideas???

    I'm confused. You know how to copy one String to the clipboard but you don't know how to copy two Strings to the clipboard.

Maybe you are looking for

  • Solaris 8 on Ultra 2 Enterprise ?

    I have an Ultra 2 Enterprise with Sun OS 5.6 on it. I'd like to upgrade it to Solaris 8. Have 512MB of RAM in it, not sure of the disk size, I'm really new to Sun. Are there any problems making the CD's or running this on an Ultra 2 that I should kno

  • Query suggestions

    Hi, I have written the following query, its taking long time to get records, SELECT VBCAR.MONTH_END_DATE,           VBCAR.SOURCE_SYSTEM,           RF1.PILLAR3_EXPOSURE_CLASS_CODE,           VBCAR.EXPOSURE_CODE,           VBCAR.EXPOSURE_CLASS_CODE,   

  • Singel Selection in Simple Table

    Hi friends I am not using an advanced table. I am using a simple table (lets say header) with 5 messagestyledtext and a singleselection bean for query purpose which i have created manually. Below this (header), I have an other table (lets say line) I

  • Chapter Numbering

    I have created a book from a bunch of InDesign files. How can I get the chapter number to increment among the files? I have found innumerable explanations how to insert a chapter number variable but not how to get the chapter to reset. I have the cha

  • Extract images from PDF

    Hi there! I neet to extract some images from PDF files! I've tried using JPedal, but it seems that they don't offer support for the free version any more, so, I couldn't use the free version! Can you tell me other tools that I can use for that scope?