出于某种奇怪的原因,当我JTree
在 java 中实现 a 时,我在 Mac OSX 上看不到扩展线(有角度);但是当树展开以显示所有节点时,我会在 Windows 上看到它们。我试过了tree.putClientProperty("JTree.lineStyle", "Angled")
,但我什么也没得到。
第二个问题,再次在 OSX 上:我有一张根的图片,也没有完全显示出来,有些东西是从顶部和底部切开的。
DefaultMutableTreeNode root = new DefaultMutableTreeNode(userId + " Album List");
albTree = new JTree(root);
albTree.setCellRenderer(new IconRenderer());
albTree.putClientProperty("JTree.lineStyle", "Angled");
albTree.setFont(new Font("Segoe UI", Font.PLAIN, 20));
albTreeModel = (DefaultTreeModel) albTree.getModel(); albTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
class IconRenderer extends DefaultTreeCellRenderer {
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
// start with default behavior
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
// customize based on local conditions/state
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
Icon openIcon = renderer.getDefaultOpenIcon();
Icon rootIcon = new ImageIcon("images/user-1.png");
if (node == nonAdminFrame.root) {
setIcon(rootIcon);
}
else if (nonAdminFrame.root.isNodeChild(node)) {
setIcon(openIcon);
}
return this;
}
}