javajtextareajformattedtextfieldrich-snippets

Code Field in Java


I trying to develop a java application to save my snippets. I want to copy codes from anywhere (like stackoverflow, netbeans, Xcode) and paste them into my application to save them with their formatting to retrieve them in future. How can achieve that? Is jTextArea supporting formatted texts (Code with colors)?

Thanks.


Solution

  • From Oracle JTextArea tutorial:

    If you want the text area to display its text using multiple fonts or other styles, you should use an editor pane or text pane. If the displayed text has a limited length and is never edited by the user, use a label.

    Which means: no, you can't use a JTextArea to format your code, use a JEditorPane or its subclass JTextPane (see this tutorial)