随笔-50  评论-55  文章-8  trackbacks-0
 在使用java默认的lokandfeel的 时候,要想让JTree不同的行显示行高,只需要cellRenderer的组件设置大小就可以了,而换作windowlookandfeel的时候,不仅要设置组件大小,对树还要设置 setRowHeight(0);
请看如下解释:
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);
以上解释来自:http://www.javaref.cn/egs/javax.swing.tree/RowHeight.html

 Related Examples
posted on 2007-11-26 10:28 蒋家狂潮 阅读(542) 评论(0)  编辑  收藏 所属分类: Swing

只有注册用户登录后才能发表评论。


网站导航: