This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Getting a character's colour from a document Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Getting a character Watch "Getting a character New topic
Author

Getting a character's colour from a document

Clive Mercer
Greenhorn

Joined: Dec 30, 2009
Posts: 10
Hi

Can someone please show me how to find out the colour of a character in a StyledDocument?

For example, I have a JTextPane and I wish to know if a certain character's foreground is Green?

Thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20080
    
  30

Did you check out the Javadoc page of StyledDocument? I think not, or you would have found the getCharacterElement(int pos) method. That returns an Element that represent the single character. From the Element you can then retrieve the AttributeSet using getAttributes().


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Clive Mercer
Greenhorn

Joined: Dec 30, 2009
Posts: 10
Funnily enough I just did exactly what you said, then I couldn't post on the forum because it was under maintenance.

Still, thank you for the very fast response!
 
Have you checked out Aspose?
 
subject: Getting a character's colour from a document
 
It's not a secret anymore!