I have a JtextArea that is 42 Columns long. When enough letters are entered by the user to fill that line of the textarea I want to count it. How can I determine how many letters will fit on the line? If I use getWidth it gives me the length in pixles. GetColums will return the number of columns, which won't do much good. I am able to count the number of characters have been entered using insertUpdate but am not sure how to determine when the end of line has been reached. any ideas?
The problem is that when tab is pressed only a tab character is inserted but the caret is advanced a number of spaces. Now the document has only one character more but the caret in the text area is nearer the right side of the component more than what would correspond to having typed only one character. That is, there is a mismatch between the douments length and the visible position of the caret. Otherwise we could use textArea.getCaretPosition or caretEvent.getDot to find out if the caret is at the end of the line. This snippet uses another approach
In the case tabs are not used within the textArea set the tab size to 0 and use the first technique.