code: protected int getRowFirstNonWhite(StyledDocument doc, int offset) throws BadLocationException {
      Element lineElement = doc.getParagraphElement(offset);
      int start = lineElement.getStartOffset();
      while (start + 1 < lineElement.getEndOffset()) {
        try {
          if (doc.getText(start, 1).charAt(0) != ' ') {
            break;
          }
        }
        catch (BadLocationException ex) {
          throw (BadLocationException)new BadLocationException("calling getText(" + start + ", " + (start + 1) + ") on doc of length: " + doc.getLength(), start)
                  .initCause(ex);
        }
        start++;
      }
      return start;
    }
docs: iterates through the text to find first nonwhite
  
  @param doc
  @param offset
  @return the offset of the first non-white
  @throws BadLocationException