aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JTextarea go to line Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextarea go to line" Watch "JTextarea go to line" New topic
Author

JTextarea go to line

Stefan Cosma
Greenhorn

Joined: Mar 30, 2012
Posts: 13

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

Joined: Jun 09, 2003
Posts: 4632
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

Joined: Mar 30, 2012
Posts: 13

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

Joined: Oct 27, 2005
Posts: 19722
    
  20

Why do you use index-2? Shouldn't that be index-1 instead?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Stefan Cosma
Greenhorn

Joined: Mar 30, 2012
Posts: 13

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
 
subject: JTextarea go to line