int (Editor editor) { Document document = editor.getDocument(); if (document.getLineCount() == 0) { return 0; } int lineNumber = editor.getCaretModel().getLogicalPosition().line; if (lineNumber >= document.getLineCount()) { return 0; } return document.getLineEndOffset(lineNumber) - document.getLineStartOffset(lineNumber); }