Jtree:如何隐藏给定的defaultmutabletreenode的文本的一部分? [英] Jtree: how to hide parts of a given defaultmutabletreenode's text?

查看:127
本文介绍了Jtree:如何隐藏给定的defaultmutabletreenode的文本的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我的JTree由以下节点组成.

Say my JTree consists of following nodes.

new DefaultMutableTreeNode("DisplayThisTextOnly {donotdisplaystringsinhere}");

如何使用TreeCellRenderer隐藏{}之间和包括{}的文本?

how can I hide the texts between and including {} from displaying using TreeCellRenderer?

当我选择此节点时,我希望能够再次获取整个字符串.

when I select this node, I want to be able to fetch the entire string again.

"DisplayThisTextOnly {donotdisplaystringsinhere}"

基本上,我的目标是能够从给定的树节点中获取其他数据,而不必setObject()

Basically my goal is to be able to fetch additional data from a given tree node without having to setObject()

推荐答案

创建自定义渲染器,并删除不想看到的文本. Swing教程中如何使用树的部分有一个示例渲染器以帮助您入门.

Create a custom renderer and strip out the text you don't want to see. The section from the Swing tutorial on How to Use Trees has an example renderer to get you started.

这篇关于Jtree:如何隐藏给定的defaultmutabletreenode的文本的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆