JTextArea Copy to System Clipboard

I have written an applet that generates RSA type 1 key pairs. The application version works correctly and outputs to files. The online applet version works but instead of writing to files I write the key data to the JTextArea hoping that it could be copied and pasted into files by the user.
The catch is that the private key (encrypted) data does not copy correctly when you use CTRL-C and then paste to Notepad. I think it has something to do with the encoded chars causing the copy to malfunction.
Take a look at the applet and the source code and let me know if you have any ideas about what might work. The main class is KeyJenApplet.java. I have tried JTextPane, JTextField and old TextArea. The old TextArea had popupmenu copy available but it was weird in that it didn't even populate the TextArea entirely when the applet was run. It populated the data much like the copy by only doing a portion of it.
http://www.cheersdata.com/keyjenapplet.html

Thanks for the responses.
I believe Windows does have a scripting language, which may well be the way to go, although so far I'm unfamiliar enough with it to be unsure.
As for the threads idea, unfortunately, I'm not programming the other application, so that won't work in this case.
Using java.awt.Robot is a good idea, and it may be the easiest, except that as you point out, the text in the clipboard would have to be broken down into keystrokes, which seems rather awkward and slow.
The other issue is how to make sure that another app becomes the active window. The Robot can presumably do it by sending keystrokes (like Alt+Tab in Windows), which require that it be the most recently active window--not always a safe assumption. Might there be a safer way?
Thanks,
Gregory

Similar Messages

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

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

  • Massive copy to system clipboard with vim?

    Say I'm editing a program with vim through a terminal (say xterm). Does anyone know how to copy the contents, via left click highlighting, onto the system clipboard (x11) when the content that needs to be copied is physically off the screen? I've tried to arrow up while highlighting but it doesn't work.

    toxic, from what I understand from t-dawg's questions is that he wants to emulate what you can do in gvim, but with vim instead.
    In gvim, I can click the mouse button; hold; drag downwards and then gvim will start scrolling downwards, whilst highlighting the passing lines. This is how you highlight large amounts of text (greater than what can fit in a single screen at a time) with a mouse.
    However, terminals are slightly dumber. Whilst you can highlight areas of text, that's a console function and not something that vim itself is monitoring. Therefore, you can't achieve the same effect with the mouse in vim as you can in gvim.
    Of course, vim is perfectly capable of selecting more text than can fit in a single screen. It has a visual mode. Press v and then move down with your cursor keys, et volia - highlighted text.
    Now when it comes to shifting this to X11's clipboard, I've never tried (hence the link I gave for possible help). I'm sure it can be done.

  • Cant copy to system clipboard

    Hi  - And thanks for reading this post.
    Web Premium CS4 /Win XP SP3 2GB RAM etc etc...
    I am stuck ! . I am no longer able to copy to the windows clipboard from PS.
    I can copy some text from a PS document and paste it into another PS document, but I cant paste it into anything else. When I right mouse click into say Notepad or DW CS4 or any other application the option to Paste is always greyed out and unavailable.
    So far I have un-installed PS CS4 and re-installed it to see if that would help. But still not working.
    Anyone seen this or got any suggestions ?
    Thanks.

    First of all, never do a reinstall until you have exhausted the many simpler possible fixes for PS problems.
    Often resetting preferences (which are not changed by a reinstall) fixes many problems. See http://forums.adobe.com/thread/375776?tstart=0
    In this case however it is a continuing, recurring problem with the Windows Clipboard that many have been frustrated by because there is no sure-fire fix.
    Apart from what ZB said sometimes purging the clipboard from within PS does it; sometimes clearing the interfering that M$ Office does, or copying a single character to clear whatever is clogging it. Over the years I have never seen a single effective fix.

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

  • System clipboard, AWT TextAreas, and JTextAreas

    This code makes a JApplet with a Swing JTextArea and an AWT TextArea. The JTextArea won't accept pasted text that was copied from another application. The AWT TextArea will. Why is this, and how can I get a JTextArea to accept pasted input?
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.util.*;
    public class TextAreaTest extends JApplet {
         Container cp = getContentPane();
         JTextArea TextIn = new JTextArea("You can't paste from the system clipboard into this box.",4,44);
         JScrollPane aScrollPane = new JScrollPane(TextIn);
         TextArea awtTextIn = new TextArea("Pasting into this box does work!",4,44);
         public void init() {
              cp.setLayout(new FlowLayout());
              cp.add(new Label("Copy some text from another program."));
              cp.add(new Label("Click in the upper box and press Shift+Insert."));
              cp.add(new Label("Why is nothing pasted?"));
              cp.add(aScrollPane);
              cp.add(awtTextIn);
    //<applet width="500" height="240" code="TextAreaTest.class"></applet>

    Thanks for checking this and replying. Pasting into the JTextArea from outside doesn't work for me, even when I'm running the applet locally. Even when I run the applet with appletviewer from the command prompt, I still can't paste from the outside into the JTextArea. If I cut from the TextArea or from an outside application and try to paste into the JTextArea, nothing happens. I can't go the other way either: If I cut from the JTextArea and try to paste into the TextArea, nothing happens. The only cutting and pasting that works with the JTextArea is that if I cut from within the JTextArea, I can paste back into the JTextArea.
    I wonder why pasting works for you and not for me. I'm using the latest JDK (1.4.2_03) and JRE on Windows XP. I have the same behavior on a Windows 2000 machine with the 1.4.1 JRE.

  • WebView -  text copied with Crtl/C or Popup Menu not in system clipboard!

    Dear JavaFX users,
    We have embedded JavaFX WebView in a Swing panel. Everything works fine, but we have realized that text selected and copied with Crtl/C or Popup Menu is not in the system clipboard.
    This is quite annoying, and we woulld appreciate any advice or suggestion for solving this issue.
    Thanks in advance,
    Best,
    Jean-Claude Dauphin

    i don't have enough space on my remote server, there are 2 other sites on this server as well.
    What are you using, FREE web hosting?
    For approx $4.95/month you can get unlimited storage and bandwidth:
    http://www.lunarpages.com/hosting-solutions/
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    http://alt-web.com/
    http://twitter.com/altweb

  • Copy an image into system clipboard takes too much memory

    Our Swing application copies a java.awt.BufferedImage into the system clipboard. Our image has a size of 1024x768 pixels and a depth of 24 bits per pixel.
    The copy from the image to the system clipboard works, but is very slow and takes too much memory. Before the copy, java.exe uses about 30 MB. After the copy, it uses about 90 MB! However, a 1024x768x3 image should consume only 2,4 MB.
    We did some debugging and it seems the AWT library does several copies of our original image in order to copy it in the system clipboard. I guess that each of these copies takes a lot of memory (probably because of a different format from the original image) and is not immediately garbage collected.
    This is a big issue for our application because the JVM throws an OutOfMemoryError when we try to copy a new image to the system clipboard.
    Here is our code. Do you have any idea? Thanks a lot for your help.
    // Create the image
    BufferedImage image = new BufferedImage(1024, 768, BufferedImage.TYPE_3BYTE_BGR);
    Graphics2D g2 = image.createGraphics();
    drawSomething(g2);
    g2.dispose();
    // Put the image into the system clipboard
    ImageSelection handler = new ImageSelection(image);
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.setContents(handler, handler);
    * An implementation of Transferable and ClipboardOwner to be used with
    * images.
    public class ImageSelection implements Transferable, ClipboardOwner {
        private static final DataFlavor flavors[] = {DataFlavor.imageFlavor};
        private Image image;
        public ImageSelection(Image imageToCopy) {
            this.image = imageToCopy;
        // Interface ClipboardOwner
        public void lostOwnership(Clipboard clipboard, Transferable transferable) {
            image = null;
        // Interface Transferable
        public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException,
                                                                IOException {
            if (isDataFlavorSupported(flavor)) {
                return image;
            else {
                throw new UnsupportedFlavorException(flavor);
        public DataFlavor[] getTransferDataFlavors() {
            return flavors;
        public boolean isDataFlavorSupported(DataFlavor flavor) {
            return flavor.equals(flavors[0]);
    }

    why dont u use other data structure to store the image , which will take less memory.

  • 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

  • Java - system clipboard problem

    I'm trying to put text from a java program to the system clipboard (OS) and I can't make it work.
    I've included a small code example in this post.
    import java.awt.datatransfer.*;
    import java.awt.*;
    import java.awt.Toolkit.*;
    class ClipTest{
    public static void main(String[] args){
    new ClipTest();
    public ClipTest(){
    StringSelection clip = new StringSelection("hello");
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    clipboard.setContents(clip,clip);
    System.exit(0);
    After running the program I would expect to have "hello" on my System clipboard. But I don't. Nothing has been transfered to the clipboard.
    I'm running java1.3.1 on IRIX and I have tryed Linux as well.
    Am I doing something wrong here? Please enlighten me.

    That's a thought. but take this code example though:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class MyTextArea extends JTextArea implements ActionListener{
    JTextArea m_txt;
    JPopupMenu m_menu;
    public MyTextArea(){
    super();
    m_txt=this;
    addMouseListener(new RightMouseListener());
    m_menu = new JPopupMenu("Menu");
    JMenu item = new JMenu("Edit");
    m_menu.add(item);
    JMenuItem item1 = new JMenuItem("Copy");
    item1.addActionListener(this);
    item1.setActionCommand("copy");
    item.add(item1);
    class RightMouseListener extends MouseAdapter{
    public void mouseClicked(MouseEvent e){
    if(e.getModifiers()==InputEvent.BUTTON3_MASK){
    m_menu.show(m_txt, e.getX(),e.getY() );
    public void actionPerformed(ActionEvent e){
    if (e.getActionCommand().equals("copy")) {
    copy();
    If you use this component in a dialog or something, type some text in it, make a selection, righclick and choose copy from the edit menu, I get the same result, and I guess it will work at your Windows platform?

  • More DataFlavors copied to the clipboard/used in D&D in one step

    Hallo,
    For my GUI app. I would like to enable different types of information to copied to the clipboard.
    e.g. object type 1 - Document ID ( actual row's document ID from JTable ) - to copy document type
    object type 2 - string representation ( columns texts from JTable ) - to copy to excel
    I would like to keep them general, with different possible combinations
    among them ( up to 10 different object types ), according to some specs.
    Has anybody idea, if it is possible ? ( prefarably with 1.4 D&D interface ).
    Data are packed in createTransferable() call, but it allows just 1 format (?) ...
    Maybe I can use some 'envelope' format holding all possible information,
    but that idea doesn't looks nice for me :(
    Thanks for any hint.
    Tibor

    Hi !
    Thanks for your help. For drag & drop it's fine. System will ask for 'best' format as I expect.
    How is it with clipboard ? I had idea to copy table columns as a "text" flavor
    ( for paste into excel ) and user created flavor "id" with documentId inside.
    On paste I would take 'what's better' ( e.g. as a document reference better would be better my "id" flavor,
    because that information doesn't need to be in table cells inside ).
    Maybe I will have to use 'own' clipboard for these reasons.
    Tibor

  • Can't copy to the clipboard in applet

    hi all,
    doing an applet application now, i figure out that when i want to copy a string to the system clipboard (i use the popup menu), JAVA console prompt out error message AccessDenied or if other case, it will prompt NoClassFound .getWindow(Unknow Source)*, this is only happen in Firefox but not IE (and i need it to work on Firefox). but in the other hand, i have another applet application where i use the button to copy the string into the clipboard in Firefox, it has no problem except ask me to enabled the "signed.applets.codebase_principal_support" value to true, then it successfully copied to the cliboard but not the popup menu applet, why?
    * this is when i didn't use java.awt.datatransfer.* but use JSObject
    anyone has idea? thanks. it seem a bit messy, i'll explain more to you if there is something miss out, thanks again

    Move off WEP to WPA or, preferably, to WPA2 (as recommended by Apple). WEP has been deprecated by the WiFi Alliance since 2004 as insecure (it can be cracked in seconds by any hacker).
    Note that each device on a network has a unique IP address but if your address starts with 169 then you did not get a valid IP address assigned to you by your router. If restarting the router did not cure the problem then you should check for a firmware update for your router.

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

Maybe you are looking for