I have a JTree populated with some (custom) nodes. I have a class that's subclass of DefaultTreeCellRenderer and using that "MyTreeCellRenderer" i can set tooltips for each node in my tree. It works fine: JTree is populated, cell renderer is set, all added nodes do have tooltips. Problem is that i don't know how to change tooltip for certain node in already populated tree... How to do that? Is there any way to "recreate" cell renderer for just one node in JTree?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
From what I understand of your question, you want to trigger the rendering of a specific node in the Tree. This should be performed through the
TreeModel
to fire the proper event (ie, treeNodesChanged). TheDefaultTreeModel
offers a utility method for that purpose: nodeChanged .However, tooltips in JTree are handled pro-actively by the JTree by reinvoking the TreeCellRenderer, meaning that nothing must be done for the tooltip to be changed. Every time the tooltip needs to be displayed, the rendering for the given node is performed. See this example that continuously updates its tooltip (simply by moving the mouse around the nodes of the tree).
I did it! Instead of using extended CellRenderer i used "getTooltipText" method of tree (i extended the tree). That way i was able to control text of tooltip according to object that has mouse pointer over it.
You will also need to tell the tooltip manager about your tree before the tooltips will render: