import javax.swing.JTextPane; import javax.swing.text.JTextComponent; import javax.swing.text.View; public class Main { public static void main(String[] argv) { JTextComponent textComp = new JTextPane(); View v = textComp.getUI().getRootView(textComp); walkView(v, 0); } public static void walkView(View view, int level) { int n = view.getViewCount(); for (int i = 0; i < n; i++) { walkView(view.getView(i), level + 1); } } }