File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Text Area Problem... Pls Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Text Area Problem... Pls Help" Watch "Text Area Problem... Pls Help" New topic

Text Area Problem... Pls Help

Srinivas Nagesh

Joined: Oct 27, 2002
Posts: 19
I would like to know how to position the cursor in a textarea to the row i want to?
Greg Charles

Joined: Oct 01, 2001
Posts: 2968

Assuming that you're using JTextArea, the cursor is actually a caret, and can be set with setCaret(). Unfortunately, that takes a position, not a line number as a parameter. However, you should be able to use getLineEndOffset(), and a little bit of logic to accomplish your goal.
Srinivas Nagesh

Joined: Oct 27, 2002
Posts: 19
I am using AWT and not Swings.
[ January 15, 2003: Message edited by: Srinivas Nagesh ]
Robbie shi

Joined: Jan 05, 2003
Posts: 28
setCaret(Caret c ) is Ok
----------------------------- IDE tool : JawaBeginer
2.Java Jar tool : JavaJar
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi, I ripped the following from some old code of mine. Assume that this method exists in a class extending the TextArea class. Here it is:

kind regards
I agree. Here's the link:
subject: Text Area Problem... Pls Help
It's not a secret anymore!