Re: add highlight in pure programmatically
Peter Cheung <[email protected]> Sun, 17 Sep 2017 16:55:06 +0000
| Newsgroups | gmane.comp.java.netbeans.modules.openide.devel |
|---|---|
| Message-ID | <ME1PR01MB02608583BCCDBA40C488C9DBB5620@ME1PR01MB0260.ausprd01.prod.outlook.com> |
--_000_ME1PR01MB02608583BCCDBA40C488C9DBB5620ME1PR01MB0260ausp_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable This doesn't work too: Highlighter highlighter =3D jTextComponent.getHighlighter(); HighlightPainter highlightPainter =3D new DefaultHighlighter.DefaultHighlig= htPainter(Color.CYAN); highlighter.addHighlight(5, 10, highlightPainter); ________________________________ From: Peter Cheung <[email protected]> Sent: Monday, September 18, 2017 12:52 AM To: [email protected] Subject: [platform-dev] add highlight in pure programmatically Hi Why the following code has no effect to add highlight? EditorCookie ec =3D dataObject.getLookup().lookup(EditorCookie.class); Document doc2 =3D ec.getDocument(); OffsetsBag bag =3D new OffsetsBag(doc2, true); AttributeSet defaultColors =3D AttributesUtilities.createImmutable(StyleCon= stants.Background, new Color(0, 0, 255)); bag.addHighlight(5, 10, defaultColors); AttributeSet defaultColors2 =3D AttributesUtilities.createImmutable(StyleCo= nstants.Foreground, new Color(0, 255, 255)); bag.addHighlight(2, 5, defaultColors2); Thanks From Peter --_000_ME1PR01MB02608583BCCDBA40C488C9DBB5620ME1PR01MB0260ausp_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <html> <head> <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-8859-= 1"> <style type=3D"text/css" style=3D"display:none;"><!-- P {margin-top:0;margi= n-bottom:0;} --></style> </head> <body dir=3D"ltr"> <style type=3D"text/css" style=3D"display:none;"><!-- P {margin-top:0;margi= n-bottom:0;} --></style> <div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;= color: rgb(0, 0, 0);"> This doesn't work too:</div> <div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;= color: rgb(0, 0, 0);"> <br> </div> <div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;= color: rgb(0, 0, 0);"> <div><span class=3D"Apple-tab-span" style=3D"white-space:pre"></span>Highli= ghter highlighter =3D jTextComponent.getHighlighter();</div> <div><span class=3D"Apple-tab-span" style=3D"white-space:pre"></span>Highli= ghtPainter highlightPainter =3D new DefaultHighlighter.DefaultHighlightPain= ter(Color.CYAN);</div> <div><span class=3D"Apple-tab-span" style=3D"white-space:pre"></span>highli= ghter.addHighlight(5, 10, highlightPainter);</div> <br> </div> <hr style=3D"display:inline-block;width:98%" tabindex=3D"-1"> <div id=3D"divRplyFwdMsg" dir=3D"ltr"><font face=3D"Calibri, sans-serif" st= yle=3D"font-size:11pt" color=3D"#000000"><b>From:</b> Peter Cheung <mche= [email protected]><br> <b>Sent:</b> Monday, September 18, 2017 12:52 AM<br> <b>To:</b> [email protected]<br> <b>Subject:</b> [platform-dev] add highlight in pure programmatically</font= > <div> </div> </div> <div> <div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;= color: rgb(0, 0, 0);"> Hi</div> <div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;= color: rgb(0, 0, 0);"> Why the following code has no effect to add highlight?</div> <div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;= color: rgb(0, 0, 0);"> <br> </div> <div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;= color: rgb(0, 0, 0);"> <div><span class=3D"Apple-tab-span" style=3D"white-space:pre"></span>Editor= Cookie ec =3D dataObject.getLookup().lookup(EditorCookie.class);</div> <div><span class=3D"Apple-tab-span" style=3D"white-space:pre"></span>Docume= nt doc2 =3D ec.getDocument();</div> <div><span class=3D"Apple-tab-span" style=3D"white-space:pre"></span>Offset= sBag bag =3D new OffsetsBag(doc2, true);</div> <div><span class=3D"Apple-tab-span" style=3D"white-space:pre"></span>Attrib= uteSet defaultColors =3D AttributesUtilities.createImmutable(StyleConstants= .Background, new Color(0, 0, 255));</div> <div><span class=3D"Apple-tab-span" style=3D"white-space:pre"></span>bag.ad= dHighlight(5, 10, defaultColors);</div> <div><span class=3D"Apple-tab-span" style=3D"white-space:pre"></span>Attrib= uteSet defaultColors2 =3D AttributesUtilities.createImmutable(StyleConstant= s.Foreground, new Color(0, 255, 255));</div> <div><span class=3D"Apple-tab-span" style=3D"white-space:pre"></span>bag.ad= dHighlight(2, 5, defaultColors2);</div> <br> </div> <div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;= color: rgb(0, 0, 0);"> Thanks</div> <div style=3D"font-family: Calibri, Helvetica, sans-serif; font-size: 12pt;= color: rgb(0, 0, 0);"> From Peter</div> </div> </body> </html> --_000_ME1PR01MB02608583BCCDBA40C488C9DBB5620ME1PR01MB0260ausp_--