• Post Reply Bookmark Topic Watch Topic
  • New Topic

General question on ListCellRenderer (or perhaps Renderer in general)

 
Jason Richard
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MyRenderer extends JLabel implements ListCellRenderer


I have a fairly complicated renderer, that checks several variables, and also may be checking a database fairly often.

Thus far I"m early into my project, and I don't feel like there is any real performance hits that I'm concerned with.

However

When I'm debugging , and I throw in a logging statement, I see that the renderer is being constantly hit even if nothing is happening, hands off keyboard.

I Understand that this is going to fire whenever it feels it needs to, but is there a way to have it only execute when something does actually change, like getValueIsAdjusting works for a ListSelectionListener? Or am I just at the mercy of the Renderer.

 
Rob Camick
Ranch Hand
Posts: 2699
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
may be checking a database fairly often.


Never do that in a renderer. The code in a renderer should always be very efficient since as you have noted it is continually called when Swing determines it needs to be called.

It is obviously called whenever the row selection changes since it needs to repaint the previous selection to remove the highlighting and paint the new row with selection.

But it is also called when you just hover the mouse over a cell, because potentially the cell could be using a tooltip and the renderer will allow you to use the setToolTipText(...) method every time it is invoked.

So yes you are at the mercy of Swing, since it determines when the renderer is invoked.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!