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
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply 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
Saloon Keeper

Joined: Oct 27, 2005
Posts: 18365

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
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!
 
 
subject: Getting a character's colour from a document
 
Threads others viewed
setting character width gap between characters in jtextpane
GUI
Very Urgent
What is the Initial value of char literal?
Text in different colours
developer file tools