swing - Java - Highlighting Text Between two Chars - JTextPane -
i need able highlight words within 2 chars. example, :
//highlight whatever in between 2 quotation marks string keychars = " \" \" ";   i have been grueling on weeks now. i've looked up, read source codes, wrote code, , still have yet find out how able this.
the following code snippet works.
ed=new jeditorpane(); ed.settext("this \"text\" contains \"quotes\". \"contents\" of highlighted"); pattern pl; pl=pattern.compile("\""); matcher matcher = pl.matcher(ed.gettext()); int end=0,beg=0; while(matcher.find()) {     beg=matcher.start();     matcher.find(); //finding next quote     end=matcher.start();     defaulthighlightpainter d =  new defaulthighlightpainter(color.yellow);     try {         ed.gethighlighter().addhighlight(beg+1, end,d);     } catch (badlocationexception ex) {         ex.printstacktrace();     } }      
Comments
Post a Comment