Java Paste From Clipboard Not Working In Every App On Linux

169 Views Asked by At

I have a Swing app written in Java 5 for an old openSuse 10.0 system and I'm trying to copy some text from a JTextArea to the clipboard and paste it in another app. The paste function works in a normal text editor, but I can't paste the copied text into another app on that system. This is the code that I use to copy the text to clipboard on button press:

   copyTextToClipboardButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String myString = decodedTextArea.getText();
            StringSelection stringSelection = new StringSelection(myString);
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            clipboard.setContents(stringSelection, null);
        }
    });

How can I fix this?

Note: I can paste the copied text in another text editor and then copy it from there and paste it into the other app, but I want to be able to paste the copied text directly

Edit: the JTextArea has editable set to false, lineWrap set to true and wrapStyleWord set to true

0

There are 0 best solutions below