0

这句话是什么意思。

ToolTipManager.sharedInstance().registerComponent(jTree);

我们是否也可以使用给定的语句注册超级组件,这样我们就不需要注册所有继承已注册超类的单个组件。

4

1 回答 1

2

实际上,当我说 JTree 总是向管理器注册自己时我是错误的(就像 JTable 一样):您必须手动完成实现提供每个节点工具提示的自定义渲染器:

JTree tree = new JTree();
// need to register manually 
// (that is does _not_ automatically as f.i. JTable
// either register the tree
ToolTipManager.sharedInstance().registerComponent(tree);
// or set a not-null tooltip text to the tree
// tree.setToolTipText("default if node has none or outside node");
TreeCellRenderer r = new DefaultTreeCellRenderer() {

    @Override
    public Component getTreeCellRendererComponent(JTree tree,
            Object value, boolean sel, boolean expanded, boolean leaf,
            int row, boolean hasFocus) {
        super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf,
                row, hasFocus);
        setToolTipText("I'm a leaf: " + leaf);
        return this;
    }

};
tree.setCellRenderer(r);
于 2013-04-09T11:33:37.887 回答