• Post Reply Bookmark Topic Watch Topic
  • New Topic

Documents Won't Color  RSS feed

 
Atrus Greyor
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With the code



It refuses to color the text. What am I missing?
[ August 26, 2007: Message edited by: Atrus Greyor ]
 
Brian Cole
Author
Ranch Hand
Posts: 949
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code is not complete (is 'pane' a reference to 'p'?) so it's hard to know for sure, but I would guess that your EditorPane's Document is an instance of PlainDocument and therefore is ignoring style.

Things you can try that should work:

a) pane = new JTextPane(); // use JTextPane, not JEditorPane

or

b) JEditorPane pane = new JEditorPane();
pane.setEditorKit(new StyledEditorKit()); // force DefaultStyledDocument

While I'm here I feel I should point out some other things:

1) The variable 'top' should probably be called 'length'. [Or the 2nd parameter to getText() should be (top-bottom).]

2) Presuming d is already pane's Document, pane.setDocument(d) should not be necessary.

3) If your Document implements StyledDocument (which it should) then you can apply attributes to a range of text without having to perform a deletion and re-insertion by calling its setCharacterAttributes() method.
 
Atrus Greyor
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I'm sorry about that. I did not want to post all of the code that was in that particular class, and just gave the essentials. Those small errors were due to a lack of good proofreading.

However, the suggestions you gave me worked, even with my faulty typing

Thanks for the help!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!