This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTextarea go to line

 
Stefan Cosma
Greenhorn
Posts: 13
Java Opera Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys,

I have a problem.

How can I jump to a specific line (using the line specified in a JTextfield) in a JTextarea ?

This is what I have so far, but it doesn't seem to work.

 
Michael Dunn
Ranch Hand
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
line numbers are 0-based, and if you have line wrap set, it won't count as additional lines



where '3' is the 4th line
 
Stefan Cosma
Greenhorn
Posts: 13
Java Opera Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I finally got it working, thanks Michael for your help.

Maybe somebody will need the following code. This is how I did it.

 
Rob Spoor
Sheriff
Pie
Posts: 20380
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you use index-2? Shouldn't that be index-1 instead?
 
Stefan Cosma
Greenhorn
Posts: 13
Java Opera Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well believe it or not, index-2 works. Initially I used index-1 but it didn't set the caret to the correct line.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic