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
posted
0
Looking at the documentation for TextArea we find the method insert(String, int). For the int parameter, use getCaretPosition(). Here's an example:
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
posted
0
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
posted
0
Thanx for help, dirk. It worx!!! [ March 28, 2002: Message edited by: da funky chicken ]