Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Text highlighting  RSS feed

 
Mathew Mintalm
Ranch Hand
Posts: 103
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I would like to ask once again. So I need little example how can I create my OWN syntax highlighting.

I dont need any ready made highlighting class ot something like this.

If someone can help me, I just need one example. I have JTextPane, and if there is word "something" it should highlighting it at red (change font color for this word only)

Just little example, please. Thanks in advice.
 
Rob Camick
Ranch Hand
Posts: 2753
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then read the JTextPane API and you will find a link to the Swing tutorial which shows you how to use "attributes" to color pieces of text.
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Furthermore, use a DocumentFilter to intercept changes to the Document so you can find word boundaries. For instance, when you add text at location x, you need to check backwards from x for the last word boundary, check for the next word boundary after the inserted text, and parse the text in between. For instance, when the current text is "public vod main" and you insert one "i" between the "o" and the "d", all you need to check is that one word (void); you can skip "public" (already highlighted) and "main".
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!