wood burning stoves 2.0*
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
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: 19682
    
  20

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
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting a character's colour from a document