Java SWT StyledText, changing the starting line number -


i using styledtext widget display "excerpt" of actual code, such method definition within java file.

my problem line number shown in styledtext start 1, different actual line number in original file. example, if original source looks like:

1:  package something; 2:   3:  public class myclass { 4:      public void foo() { 5:          // something... 6:      } 7:  } 

then, when foo() method shown in styledtext widget, want show line numbers starting 4, not 1.

is there way achieve this? read through javadoc, not figure out way.

just change linestyleevent.bulletindex in linestylelistener:

final styledtext text = new styledtext(shell, swt.none);  text.settext("lalala\n\nlalala\n\nlalala\n\nlalala\n\nlalala\n\nlalala\n\n"); text.addlinestylelistener(new linestylelistener() {     @override     public void linegetstyle(linestyleevent e)     {         // set line number         e.bulletindex = text.getlineatoffset(e.lineoffset);          // set style, 12 pixles wide each digit         stylerange style = new stylerange();         style.metrics = new glyphmetrics(0, 0, integer.tostring(text.getlinecount() + 1).length() * 12);          // create , set bullet         e.bullet = new bullet(st.bullet_number, style);          // apply offset         e.bulletindex += your_offset; // used 3 here     } }); 

looks this:

enter image description here


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -