This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

line number in JTextArea

 
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!