Jtree: how to hide parts of a given defaultmutabletreenode's text?

折月煮酒 提交于 2020-01-07 05:36:06

问题


Say my JTree consists of following nodes.

new DefaultMutableTreeNode("DisplayThisTextOnly {donotdisplaystringsinhere}");

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}"

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


回答1:


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.



来源:https://stackoverflow.com/questions/7962252/jtree-how-to-hide-parts-of-a-given-defaultmutabletreenodes-text

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!