File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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: 19674
    
  18

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!
 
wood burning stoves
 
subject: Getting a character's colour from a document