• Post Reply Bookmark Topic Watch Topic
  • New Topic

line number in JTextArea  RSS feed

 
Jain Neeraj
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can i put line numbers in JTextArea (like we have in general editors like WordPad or EditPlus etc...)???
N.
 
Rene Liebmann
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
nice idea, but I think, you can't put your line numbers inside the JTestArea. The JTextArea displays a String and it breaks the lines short before the right end of the area appears. If you want to display your line numbers inside the area, you need to modify the string. This is not so good.
So you need a different component to display the numbers. And you have to calculate the number of lines. I did this in a printing api which was able to print text (There I also had to calculate, how many lines will fit on one page and how many pages I will have)
I did this with the LineBreakMeasurer. Please have a look to the API to see examples how it works.
Hope this helps

Rene
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!