简体   繁体   中英

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

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()

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM