-1

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.

Sasal
  • 3
  • 2

1 Answers1

0

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)

Bruno Zamengo
  • 800
  • 1
  • 11
  • 24
  • I will see the tutorial, thank you very much bro. Now I asking, if there is a way to save the text with its format in database, and when it wii be retrieved, the text will be formatted as in the first case? – Sasal Dec 25 '16 at 20:17
  • I think you have to save the text and the format into two different fields. – Bruno Zamengo Dec 26 '16 at 10:44
  • And no, you can't retrive it "formatted": you have to teach the component how it has to format your text. Again, see the tutorial (and google a bit before asking questions... ;) ). – Bruno Zamengo Dec 26 '16 at 10:46
  • OK my dear, thank you very much :| – Sasal Dec 26 '16 at 11:22