3

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.

(I'm familiar with the concept of a TableCellRenderer)

Is there a way to do this just for the cells in question, without causing all the cells to redraw?

Jason S
  • 184,598
  • 164
  • 608
  • 970
  • right then you have to read this very [interesting thread](http://stackoverflow.com/a/9607805/714968), please whole thread, answer by (@kleopatra) too, not only linked post by (@Hovercraft Full Of Eels :-) – mKorbel Mar 08 '12 at 20:06
  • 2
    `JTable`'s flyweight rendering is already fairly efficient, but see also [*Christmas Tree Applications*](http://java.sun.com/products/jfc/tsc/articles/ChristmasTree/). – trashgod Mar 08 '12 at 20:13
  • agreed! thank you -- please post as an answer – Jason S Mar 08 '12 at 20:16
  • *"a large JTable (20x16!)"* OMG dude! I don't think anybody has ever tried to show a table with 320 cells or more in Java before. Had you considered other languages better suited to this mammoth task? ROTFL.. – Andrew Thompson Mar 09 '12 at 04:26
  • Looking closer, `20 x 16 = 320`, but `20 x 16! = 502146957312000`. Please clarify. – trashgod Mar 09 '12 at 06:51
  • how exactly are you achieving the blink? And where exactly is your _measured_ performance bottleneck? – kleopatra Mar 09 '12 at 12:39
  • @Andrew: I meant large from a user visibility standpoint. – Jason S Mar 09 '12 at 13:19
  • @kleopatra: I haven't done it yet. I do Java programming only for a small part of my job, and can't afford to implement something only to find that it takes up 20 or 30% of the CPU and that I have to start over. I like to educate myself *before* starting on a programming task. – Jason S Mar 09 '12 at 13:21
  • @trashgod: oh, come on, be reasonable. 502 trillion won't fit in an `int` (JTable/TableModel row + column indices are `int`) and that number of rows would have trouble navigating with scrollbars, let alone the issues caused by having to manage ultra-large amounts of data. – Jason S Mar 09 '12 at 13:26
  • Fair enough; I may be a _little_ jaded. – trashgod Mar 10 '12 at 02:49

1 Answers1

3

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.

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.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • 1
    arrgghh ... that old article again ... note that its bottom-line is: not much to gain whatever dirty short-cuts we might try :-) – kleopatra Mar 09 '12 at 12:36