Here you can find the source of getLineTabs(StyledDocument doc, int startOffset)
public static String getLineTabs(StyledDocument doc, int startOffset)
//package com.java2s; //License from project: Apache License import javax.swing.text.BadLocationException; import javax.swing.text.StyledDocument; public class Main { public static String getLineTabs(StyledDocument doc, int startOffset) { int i = startOffset; String s;// ww w. j a v a 2 s . co m try { do { s = doc.getText(i, 1); if ((i > 0 && !"\n".equals(s))) {//NOI18N i--; } else { break; } } while (true); StringBuilder tabs = new StringBuilder(); i++; do { s = doc.getText(i, 1); if (" ".equals(s) || "\t".equals(s)) {//NOI18N tabs.append(s); } else if (Character.isJavaIdentifierPart(s.charAt(0))) { break; } i++; } while (i < doc.getLength()); return tabs.toString(); } catch (BadLocationException ex) { throw new RuntimeException(ex);//should never happen } } }