1

我需要一个只有叶节点可以编辑的 JTree。但我不知道如何进行自定义设置。有没有人可以帮忙?谢谢!

4

1 回答 1

5

You can override the isCellEditable() method of DefaultTreeCellEditor in a way that limits editing to leaf nodes, as shown in this example.

@Override
public boolean isCellEditable(EventObject e) {
    return super.isCellEditable(e)
        && ((TreeNode) lastPath.getLastPathComponent()).isLeaf();
}
于 2012-11-30T03:44:38.950 回答