2

How can I extend JTextArea to indent the first line? I would like to display some non-editable things in the upperleft corner area of the text area (e.g. some icons). These items would be the height of one line of text, so if JTextArea were to leave part of the first line blank, these items could be layed out there. The field must be editable and multiline.

I've spent a few days looking through the hierarchy of text classes and UI classes. I have a general understanding of this architecture - uses Document to store the text, the DefaultTextUI does the painting & tracks the caret and so on. It just gets messier and messier, though, to dig down into the character positioning code.

I think I could start from scratch, extending Component, but this seems like the wrong approach. Anyone feel confident enough to help with the "right" way? I might be willing to compensate if we take off the forum.

Peri Hartman
  • 19,314
  • 18
  • 55
  • 101

1 Answers1

2

You don't need to extend anything. Have a look at the JEditorPane class. It is capable of displaying text, images etc.

Qwerky
  • 18,217
  • 6
  • 44
  • 80
  • 1
    See these [2 examples](http://stackoverflow.com/questions/6373621/loading-images-from-jars-for-swing-html/6373907#6373907). – Andrew Thompson Nov 08 '11 at 16:22
  • Thanks! I don't know why, but I thought it was a readonly component. I just installed it into my app and it basically works, but I have a some fiddling to do to get it to resize properly and try the indent and layout functionality. – Peri Hartman Nov 08 '11 at 16:42