jtree使用户通过“闪烁"查看更新. (颜色快速变化) [英] jtree make user see updates via "blinking" (rapid change of color)

查看:86
本文介绍了jtree使用户通过“闪烁"查看更新. (颜色快速变化)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JTree呈现信息(通过DefaultMutableTreeModel).
此信息来自用户操作或异步 网络上的邮件.
我的问题是,是否可以使树节点的文本开始闪烁"(我想这是颜色的快速变化),以便使用户收到已添加新内容的警报?如果是,怎么办?

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?

谢谢!

推荐答案

问题有两个部分.

  1. 检测最近更改的节点. 您可以将TreeModelListener添加到模型中,并获取已更改/已插入节点的列表.

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

闪烁. 创建一个自定义渲染器,该渲染器可以根据眨眼状态以两种颜色渲染同一节点(例如,将背景或前景从黑到红并向后切换).在渲染器中,检查节点是否已更改(在列表中),并将背景设置为红色.

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.

添加javax.swing.Timer每隔0.5秒更改颜色,并调用节点区域的重绘(使用JTreegetRowBoundsgetPathBunds方法).

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

这篇关于jtree使用户通过“闪烁"查看更新. (颜色快速变化)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆