Results 1 to 4 of 4
  1. #1
    cultclassic is offline Member
    Join Date
    Mar 2011
    Rep Power


    Hi, I want to give Clipboard access to an applet.
    I edited <JAVA_HOME>\jre6\lib\security\java.policy
    file to add:

    grant codeBase "*" {
    permission java.awt.AWTPermission "accessClipboard";

    It still throws

    when I add the permission to the global

    grant {

    area, it works. But for obvious security reasons
    I want to limit the access to some domains.

    Am I missing something? I also tried
    grant codeBase ""
    grant codeBase ""
    but nothing works... Any Ideas?


    BTW the applet is NOT signed.

    Here a sample code for the problem:
    Java Code:
    import java.applet.*;
    import java.awt.*;
    import java.awt.datatransfer.Clipboard;
    import java.awt.datatransfer.StringSelection;
    import java.awt.datatransfer.ClipboardOwner;
    import java.awt.datatransfer.Transferable;
    import java.awt.Toolkit;
    public class Clippy extends Applet implements ClipboardOwner
    		public void init() 
    		public void stop() 
    		public void paint(Graphics g) 
    		public static String getCustomStackTrace(Throwable aThrowable) {
    			//add the class name and any message passed to constructor
    			final StringBuilder result = new StringBuilder( "EXCEPTION: " );
    			final String NEW_LINE = System.getProperty("line.separator");
    			//add each element of the stack trace
    			for (StackTraceElement element : aThrowable.getStackTrace() ){
    			result.append( element );
    			result.append( NEW_LINE );
    			return result.toString();
    		public void copyToClipBoard(String content) {
    			Graphics g = getGraphics();	
    				Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    				StringSelection stringSelection = new StringSelection(content);
    				g.drawString("Copied!!!", 10, 10);
    			catch (Exception e)
    				g.drawString(getCustomStackTrace(e), 10, 10);
    		public void lostOwnership( Clipboard aClipboard, Transferable aContents) {
    		//do nothing
    Java Code:
    function getScreenDimension() {
    <INPUT type="button" value="call Java Applet method" 
       onClick = "document.clip.copyToClipBoard('dadada');">
    <applet codebase=""  code=Clippy name="clip" id="Clippy" width=400 height=200 mayscript="true" scriptable="true">
    <param name="scriptable" value="true" />
    Last edited by cultclassic; 05-11-2011 at 10:31 PM.

  2. #2
    cultclassic is offline Member
    Join Date
    Mar 2011
    Rep Power

    Default Permission on policy file

    For some reason, the first post appeared after the second post... So I combined them both above...
    Last edited by cultclassic; 05-11-2011 at 11:03 PM.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power


    I ran a test and was able to have the applet code copy to the clipboard when the copy... method was called in the start method. It fails when called on the button push.
    I added a param to the html for the applet: <param name="DoCopy" value="true" />
    The in start:
    Java Code:
          public void start() {
             // Fake a call if requested
             String doit = getParameter("DoCopy");
             if(doit != null && doit.equals("true"))
                copyToClipBoard("Copied from Applet");
    My .java.policy file entry:

    grant codeBase "file:/D:/JavaDevelopment/Testing/ForumQuestions5/-" {
    permission java.awt.AWTPermission "accessClipboard";

    The java console shows:

    Java Plug-in 1.6.0_20
    Using JRE version 1.6.0_20-b02 Java HotSpot(TM) Client VM
    User home directory = C:\Documents and Settings\Owner

    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    o: trigger logging
    q: hide console
    r: reload policy configuration
    s: dump system and deployment properties
    t: dump thread list
    v: dump thread stack
    x: clear classloader cache
    0-5: set trace level to <n>

    Copying!! content=Copied from Applet<

    I added the text of content and the println for "copied!" so the output shows on the log

    I'm using Firefox.

  4. #4
    cultclassic is offline Member
    Join Date
    Mar 2011
    Rep Power


    Whoa! Interesting! Thanks Norm...

    I did some more experimentation. On a hunch, I made the clipboard object a class variable and initialized it on init();
    Now it works, even from the Javascript call.

    Have no clue why, have to look in to it.

Similar Threads

  1. File Permission Problem
    By ProgrammingPup in forum Java Applets
    Replies: 2
    Last Post: 12-30-2009, 12:48 AM
  2. File Permission Problem
    By ProgrammingPup in forum Advanced Java
    Replies: 1
    Last Post: 12-29-2009, 06:05 PM
  3. Replies: 1
    Last Post: 10-16-2008, 10:56 PM
    By willemjav in forum Java Applets
    Replies: 1
    Last Post: 03-09-2008, 02:57 AM
    By willemjav in forum NetBeans
    Replies: 0
    Last Post: 03-09-2008, 02:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts