Swing:一种使表中的特定单元格闪烁的最有效的计算方法 [英] Swing: most computationally-efficient way to blink particular cells in a table
问题描述
我需要一种方法来吸引人们注意大型JTable(20x16!)中的特定单元格,并且我想知道文本闪烁所需的内容,例如开启900毫秒,关闭100毫秒.
I need a way to draw attention to particular cells in a large JTable (20x16!), and I want to know what it would take for the text to blink, e.g. 900msec on and 100msec off.
(我熟悉是否有一种方法可以仅针对所讨论的单元格执行此操作,而不会导致所有单元格都重新绘制?
Is there a way to do this just for the cells in question, without causing all the cells to redraw?
推荐答案
所需的占空比(打开900毫秒,关闭100毫秒)和计数(20 x 16)在 JTable
的能力范围内>渲染,它使用 flyweight模式 来提高效率.在极少数情况下需要进行性能分析时,请参见文章 圣诞树应用 .另请参见使用 prepareRenderer()
方法的比较.
The required duty cycle (900 ms on, 100 ms off) and count (20 x 16) is well within the capability of JTable
rendering, which uses the flyweight pattern for efficiency. On the rare occasion when profiling warrants, see the article Christmas Tree Applications. See also this comparison with the prepareRenderer()
approach.
附录:还要考虑 JLabel
的 GridLayout
,每个按钮都具有自己的 javax.swing.Timer
实例,以避免同步闪烁.计时器共享一个公共线程.
Addendum: Also consider a GridLayout
of JLabel
, with each button having it's own instance of javax.swing.Timer
to avoid synchronous blinking. The timers share a common thread.
这篇关于Swing:一种使表中的特定单元格闪烁的最有效的计算方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!