0

I want to print mathematical solutions, questions and answers, both in Bold and plain text in my JTextArea How do I print symbols like exponent 2, matrix symbols, etc? Something like this:

enter image description here

What is the shortest, smartest way to accomplish this type of text in JTextArea? Having both bigger fonts, smaller fonts wrapped together with few headings bold and having symbols too. Please pardon me if the question is childish :( SO is always my last and ultimate choice of getting answers to my questions.

Ingila Ejaz
  • 399
  • 7
  • 25
  • 2
    There are some suggestions [here](http://stackoverflow.com/q/7448216/230513) and [here](http://stackoverflow.com/q/456002/230513), but opinions vary on shortest & smartest. – trashgod Aug 23 '14 at 05:59
  • 1
    A `JTextArea` is for plain text. It does not support distinctions between **bold** and plain text. For that we need to use `JEditorPane` or `JTextPane`. – Andrew Thompson Aug 23 '14 at 06:06
  • Maybe the shortest way is to let users "upload" and insert images of the equations to the JTextPane (instead of JTextArea). – Jaec Aug 23 '14 at 06:08
  • @Jaec the content is not static. Equations are generated at runtime. SO I cannot take images of it. – Ingila Ejaz Aug 23 '14 at 06:30

1 Answers1

1

I was doing it wrong. JTextArea is for simple text. If you want to add bold, italic text and/or special characters to your text, use JEditPane() or JTextPane() , do all your styling stuff in StyledDocument and finally add StyledDocument to yourJTextPane or JEditPane

For readres who might be confused about these things. A lot of good examples can be found here

Ingila Ejaz
  • 399
  • 7
  • 25