0

Alright, so I would like to do this: Make parts of a JTextArea non editable (not the whole JTextArea!)

But on a JTextPane instead of a JTextArea, which does not seem to be possible using a DocumentFilter (?).

I tried the above solution on a JTextArea, and it works wonders. But I just can't find anything about how to do this on a JTextPane (if at all possible).

Well I did find this post: Adding text to a JTextPane without having it editable by the user?

But that's not quite what I'm looking for - I need my JTextPane to behave like a command prompt, like the JTextArea in the first link.

Any help would be greatly appreciated, thanks!

Community
  • 1
  • 1
Saphiras
  • 33
  • 5

1 Answers1

1

If you need a J*Pane of sorts - use JEditorPane. You can then use a DocumentBuilder and control its index so it will function much in the same way as your JTextArea example.

Mitch Connor
  • 766
  • 10
  • 19
  • Does the JEditorPane support HTML formatting, buttons, icons etc? What's special with the EditorPane? – Saphiras Jul 17 '12 at 21:13
  • Absolutely! That is its main purpose. You set the 'document' of the JEditorPane in its constructor or dynamically by passing it to the constructor and the parameter "html/text". It supports everything short of complex CSS. Feel free to message me for more help ;) – Mitch Connor Jul 17 '12 at 21:20
  • Do you happen to have a good tutorial on your hands on how to use a DocumentBuilder? Or should I just visit google already ;)? – Saphiras Jul 17 '12 at 21:30
  • Well Ill consider my answer the accepted one I guess :) With Document Builder you just specify its type (for HTML: "html/text") and then append strings to the document builder such as "Hello". However, the first thing that goes into the document has to be the string "" and the last thing "". You should have no trouble using it right off but I do recommend that you look at the Java API for DocumentBuilder. – Mitch Connor Jul 17 '12 at 21:37
  • Yeah, if anything, it appears the JEditorPane works well with a DocumentFilter - and a good solution as to how to make parts of a text component uneditable using a DocumentFilter has already been brought up. So, yeah, answer accepted :P – Saphiras Jul 17 '12 at 22:20