// Create a text component
JTextComponent textComp = new JTextPane();

// Get the root view
View v = textComp.getUI().getRootView(textComp);

// Walk the view hierarchy
walkView(v, 0);
// Recursively walks a view hierarchy
public void walkView(View view, int level) {
    // Process view...

    // Get number of children views
    int n = view.getViewCount();

    // Visit the children of this view
    for (int i=0; i<n; i++) {
        walkView(view.getView(i), level+1);

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.