?在使用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
posted on 2007-11-26 10:28
蔣家狂潮 閱讀(550)
評論(0) 編輯 收藏 所屬分類:
Swing