int (final int line) { if (line == myTextArea.getLineCount()-1) { return 0; } try { int l = 0; String text = getText(); for (int pos = myTextArea.getLineEndOffset(line) - 1; pos >= myTextArea.getLineStartOffset(line); pos--) { if (text.charAt(pos) != '\r' && text.charAt(pos) != '\n') break; l++; } return l; } catch (BadLocationException e) { throw new RuntimeException(e); } }