jtree make user see updates via “blinking” (rapid change of color)

给你一囗甜甜゛ 提交于 2019-12-24 09:57:49

问题


I have a JTree presenting information (via DefaultMutableTreeModel).
This information is either from user actions or from asynchronous messages over the network.
My question is, is it possible to make the text of a tree node to start "blinking" (I guess this is a rapid change of color) so that the user is alerted that something new has beed added? If yes how?

Thanks!


回答1:


There are 2 parts of the problem.

  1. Detecting recently changed nodes. You can add TreeModelListener to your model and get list of changed/inserted nodes.

  2. Blinking. Create a custom renderer which can render the same node in two colors depending on blink state (e.g. background or foreground is swithed black to red and back). In the renderer check whether the node was changed (present in the list) and set background to red.

Add a javax.swing.Timer to change color each 0.5 sec, and call repaint of the nodes regions (use getRowBounds or getPathBunds method of JTree).



来源:https://stackoverflow.com/questions/4506780/jtree-make-user-see-updates-via-blinking-rapid-change-of-color

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