#1
  1. Wiser? Not exactly.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    5,938
    Rep Power
    4033

    Interact with System clipboard from applet.


    Hi

    This may not even be possible, but I'm not sure. I am trying to make an app that will be used to view documents online. It should be possible for people to copy the text from these documents to another program if they want, but I need to be able to control what they copy and append some information to the text (a citation really)

    For example, say one were viewing this post and wanted to copy something out of it. The app should allow the copy, but add a citation after it so when pasted into the other program it looks like:

    "This may not even be possible, but I'm not sure."

    Interact with System clipboard from applet. http://forums.devshed.com/... p1 13 Oct 2006

    To do that I need to
    1) Be able to set the system clipboard, which I can't do from an applet due to security restrictions (works as an app)

    2) Intercept ctrl+c to run my own copy function which can create and append the citation text.


    Is this possible at all using java, or would I be forced into doing something with activex or something else?

    I'm thinking the first point should be possible, though I may need to sign the applet or something, which I don't know how to do and the info I have been able to find online seems to all be outdated or doesn't work anyway.
    Recycle your old CD's, don't just trash them



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2005
    Posts
    191
    Rep Power
    82
    I'm no expert on Java applet security, but I suspect signing the applet may be the only way around this in pure Java.

    Have you noticed that you can set and examine the clipboard contents in JavaScript?

    Code:
    function SetClipBoard(x) {
       window.clipboardData.setData("text",x);
    }
    You might be able to use something like this to pass data to/from your applet?
  4. #3
  5. Wiser? Not exactly.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    5,938
    Rep Power
    4033
    Signing the applet seems to have worked well. Incase anyone wants to know, here's a little .bat file I made which compiles the class, packes it in the archive and signs it. Might be useful to people looking to see how to sign an applet.

    Code:
    @echo off
    echo Cleaning environment...
    del *.class
    del *.jar
    echo Compiling...
    javac applet1.java
    if not %ERRORLEVEL% == 0 (
    	echo Compile failed.
    	goto done
    )
    
    echo Packaging
    jar cvf MyApplet.jar .
    echo Signing...
    jarsigner MyApplet.jar mykey -keypass abcdef
    
    if %ERRORLEVEL% == 0 (
    	echo Running...
    	start http://localhost:8008/java/applet1.html
    ) else (
    	echo Signing failed
    )
    
    
    :done
    You have to setup the key first, which you can see how to do that from this page in the sun documentation

    Comments on this post

    • tfecw agrees
    Recycle your old CD's, don't just trash them



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud

IMN logo majestic logo threadwatch logo seochat tools logo