Can you use copy and paste commands with java?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Can you use copy and paste commands with java?

  1. #1
    Join Date
    Jan 2005
    Location
    In A Perfect Cadence
    Posts
    5

    Question Can you use copy and paste commands with java?

    I am writing a small program, I would want the final product (which probably will be an applet (not totally sure about that bit)), to have a text field and the user would be able to copy text from a file from their P.C. and transfer it into the applet via the paste command. Thing is I am not sure if copy & paste work with java, any ideas, Dave.

  2. #2
    Join Date
    Sep 2002
    Posts
    78
    you would have to use the system clipboard

    here is a snippet of code i found on the internet:

    Code:
    public void clpbrd() 
       { 
           System.out.println("Clipboard stuff"); 
           try 
           { 
    //blah blah
               Clipboard clip = this.getToolkit().getSystemClipboard(); 
       
               if(clip == null) throw new IOException("No clipboard in scene"); 
        //blah blah
               Transferable trans = clip.getContents(this); 
       //blah blah
               if( trans == null) throw new IOException("Clipboard Empty"); 
        //******************
               String s = (String) trans.getTransferData(DataFlavor.stringFlavor); 
    //***************
               _textArea.replaceRange(s, _textArea.getSelectionStart(), 
                                             _textArea.getSelectionEnd()); 
           } 
           catch(Exception e) 
           { 
    //do smthng.   
           } 
       }
    hope it helps
    ¿Red Baron?
    [code] /* dont forget code tags! */ [/code]
    Come visit the Café!

  3. #3
    Join Date
    Aug 2002
    Posts
    94
    Hi,
    last time I tried using system clipboard for copy and paste operation in a java aplet it gave security exception error. It violates the sandbag security model of applets.

    I was using jdk 1.2 (in 1999) and I don't expect much as changed in jdk1.4 however you can extend the security model by using "policytool".
    bye

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center