boolean (Caret caret) { final Document doc = caret.getEditor().getDocument(); final int offset = caret.getOffset(); if (offset >= doc.getTextLength()) return false; final char c = doc.getCharsSequence().charAt(offset); return c == ' ' || c == '\t' || c == '\n'; }