Code Field in Java

57 views Asked by At

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.

1

There are 1 answers

4
Bruno Zamengo On BEST ANSWER

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)