• Post Reply Bookmark Topic Watch Topic
  • New Topic

how you would do this ?  RSS feed

 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
suppose you have a requirement like below

here you have to just color the word " how " , then how would you do it ?

and this sentence is in jtextPane (consider it as a texteditor )

note : i m not telling you to highlight , i m telling how to color the word , in any color
 
Rob Spoor
Sheriff
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With JTextPane, you can get a reference to its StyledDocument, then call setCharacterAttributes. You can create the AttributeSet as this:
 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:With JTextPane, you can get a reference to its StyledDocument, then call setCharacterAttributes. You can create the AttributeSet as this:


i have tried this , but it makes my cursor go red not the text what i typed from 0 to 5th position (as given by offset & length)

now what could i do to make my text go red ?
 
Tim Moores
Saloon Keeper
Posts: 3831
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first few results of a search for styling swing text all show in detail how to do this.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!