Search code examples
javajtextarealook-and-feel

Getting a Jtextarea to be able to be copied over


I have a question related to updating my Java version from version 6 to 7. And while there were very few changes I had to make to my program I did notice something strange. I used to be able to copy the text within the panel and paste it on a note pad if I wanted to. But with the recent Java upgrade I find that I am not able to do this any more. I made changes to the style code for it but I am not sure if there is anything I am missing and the repository does not show any change at all to it.

Here is the code, for my JTextArea:

public void SetStyleForTextAreaLabel( JTextArea ta) {
    ta.setEditable( false);
    ta.setHighlighter( null);
    ta.setLineWrap( true);
    ta.setWrapStyleWord( true);
    ta.setEnabled( false);
    ta.setDisabledTextColor( Color.black);
    ta.setBackground( this.getBackground());
}

Solution

  • You need to setEnabled(true). Also, since you are setting the highlighter to null, it may be that you cannot see what is being selected. Try this:

    public void SetStyleForTextAreaLabel( JTextArea ta) {
        ta.setEditable( false);
        ta.setLineWrap( true);
        ta.setWrapStyleWord( true);
        ta.setDisabledTextColor( Color.black);
        ta.setBackground( this.getBackground());
    }