The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.swing.text  [49 examples] > JTextComponent  [11 examples]

e978. Enumerating All the Views in a JTextComponent

    // 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);
         }
    }

 Related Examples
e968. Retrieving Text from a JTextComponent
e969. Retrieving All the Text from a JTextComponent Efficiently
e970. Modifying Text in a JTextComponent
e971. Asynchronously Reading the Contents of a Visible JTextComponent
e972. Finding Word Boundaries in a JTextComponent
e973. Retrieving the Visible Lines in a JTextComponent
e974. Using a Position in a JTextComponent
e975. Limiting the Capacity of a JTextComponent
e976. Enabling Text-Dragging on a JTextComponent
e977. Sharing a Document Between JTextComponents

See also: Actions and Key Bindings    Caret and Selection    Events    JEditorPane    JFormattedTextField    JTextArea    JTextField    JTextPane    Styles   


© 2002 Addison-Wesley.