• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to get the color of the text written in a JTextPane

 
rohit rusty
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello friends,

i have a JTextPane in which i have words of two different color, red and black. i need to perform replacement operation on the basis of which color the word is. how do we get which color the Word written in the JTextPane is.
please help.

rohitrusty314
 
Rob Spoor
Sheriff
Posts: 20817
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Get the StyledDocument, get the correct Element, then call getAttributes() on that Element.
 
rohit rusty
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:Get the StyledDocument, get the correct Element, then call getAttributes() on that Element.


thankyou. but i am not able to understand how exactly to get the correct element. for example i have following text in my JTextPane

number number number

how to identify out of the 3 elements which is the one with red. please a little more detail would be great.
and thankyou again.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!