The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.swing.tree  [15 examples] > Layout  [1 examples]

e1031. Setting the Row Height of a JTree Component

The tree component's row height property controls the height of every displayed node. If the row height is greater than 0, all rows will be given the specified height. However, if the rows can be of differing heights, it is necessary to set the row height to 0. With a 0 row height, all heights of all rows are computed individually.
    // Create tree
    JTree tree = new JTree();
    
    // All rows will be given 15 pixels of height
    tree.setRowHeight(15);
    
    // Have the row height for each row computed individually
    tree.setRowHeight(0);
    
    // If the row height is 0 and the height of a row has dynamically changed, it is necessary
    // to flush the internal cache of row heights. The following calls flush the internal cache.
    if (tree.getRowHeight() <= 0) {
        // Temporary change to non-zero height
        tree.setRowHeight(1);
    }
    tree.setRowHeight(0);

 Related Examples

See also: Events    Node Expansion    Nodes    Selections   


© 2002 Addison-Wesley.