简体   繁体   中英

Jtree must be resized to repaint the selected node

I have a JTree with a custom TreeModel (a class that implements TreeModel). The tree works correctly, apart from a single strange thing: when I click nodes or move around with the arrow keys, the tree does not repaint the selected node (there is no border around the newly selected node) and the previous selection disappears. The nodes are also drawn twice the normal height. First, I thought the tree was not responding to user input, later I discovered that after resizing the window (causing a repaint), the tree reflects correctly the changes.

What could be the cause of this behaviour?

Sorry for the question, problem solved. The issue was in the TreeModel: adding a child to a parent resulted in adding the child and also the parent itself, so the JTree had repainting problem. I implemented incorrectly the method to add a child node.

In the documentation of the TreeModel there is a revealing notice: "...If this condition is not met, painting problems and other oddities may result."

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