wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Append a text on Cursorposition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Append a text on Cursorposition" Watch "Append a text on Cursorposition" New topic
Author

Append a text on Cursorposition

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I am coding a textEditor with the awt (not with swing) and i want to insert a text on actual Cursorposition. With int nu=editor.getCaretPosition(); i will get the actual Linenumber - but HOW DO I APPEND THE TEXT ON THIS POSITION???
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Looking at the documentation for TextArea we find the method insert(String, int). For the int parameter, use getCaretPosition().
Here's an example:

Was there a hidden message in that?


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Originally posted by da funky chicken:
With ... getCaretPosition() ... i will get the actual Linenumber

That's not correct. With getCaretPosition() you get the caret position within the TextArea (or whatever TextComponent) with regards to the beginning of the String that the TextArea contains. That String begins at the top left corner. The top left corner has a position of 0. If "Hello," were at the beginning of the TextArea, and the caret were between the two 'l' characters, then getCaretPosition() would return 3 - not the line number.
Good Luck.
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
da funky chicken
Welcome to the Java Ranch, we hope you’ll enjoy visiting as a regular however,
your name is not in keeping with our naming policy here at the ranch. Please change your display name to an appropriate name as shown in the policy.
Thanks again and we hope to see you around the ranch!!


Dave
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Thanx for help, dirk. It worx!!!
[ March 28, 2002: Message edited by: da funky chicken ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Append a text on Cursorposition
 
Similar Threads
Line Feed Carriage Return problem
How to copy from 4 JTextFields to 1 JTextArea
HUGE, ENORMOUS, INCREDIBLE ERROR in K & B
Logging Tab
JTextArea indent question