• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Documents Won't Color

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic