问题
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