This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Columns vs letters

 
Craig Parsons
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jose Botella
Ranch Hand
Posts: 2120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Craig Parsons
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, that was a big help.
Thanks again.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic