<AWT Dev> <Swing Dev> Inefficiencies with custom TableCellRenderer and Applets

Shannon Hickey Shannon.Hickey at Sun.COM
Thu May 22 12:22:48 PDT 2008


Clemens Eisserer wrote:
> Hi,
> 
> I've created a library which has to use custom TableCellRenderers for
> its tables.
> I experienced a large performance difference between running my
> application as Application inside an JFrame and as an JApplet.
> Parented inside of the JFrame scrolling the table was smooth, however
> scrolling inside the applet was slow, especially if the mouse is over
> the table while scrolling.
> 
> I did some profiling with netbeans-profiler and found the root-cause:
> BasicTableUI.paintCell->CellRendererPane.paintComponent->Container.validate->Component.updateCursorImmediatly->GlobalCursorManager.updateCursorImmediatly()->_updateCursor....
> 
> The updateCursorImmediatly was called both times about 16.000 times,
> with JFrame it consumed 22% of the cycles which is already
> inefficient.
> As JApplet it calls into getLocationOnScreen() which calls down till
> XBaseWindow.toOtherWindow even slower which is about as slow as
> updating the Cursor itself, so as applet it consumes 48% of all EDT
> cycles.
> 
> The DefaultTableCellRenderer simply overrides validate with an empty
> method, therefor no such calls are done.
> But why does CellRendererPane.paintComponent() call validate at all?

CellRendererPain takes an argument that dictates whether or not it 
validates. In most cases it's told to validate by the caller since the 
renderer may need to do layout on its children.

I suggest you override validate() on your custom renderer to do nothing, 
the same way the DefaultTableCellRenderer does.

> If it cannot be avoided, is there no way to cache stuff in
> XBaseWindow.toOtherWindow at all?

You'll have to ask the AWT team about this. I've CC'd them.

Shannon

> 
> Thanks, lg Clemens
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Very simple TableCellRenderer which triggers the slowness:
> 	  JLabel renderer = new JLabel();
> 	  public Component getTableCellRendererComponent(JTable table, Object value,
> 	      boolean isSelected, boolean hasFocus, int row, int column) {
> 		 renderer.setText((String)value);
> 		 renderer.setOpaque(true);
> 	    return renderer;
> 	  }

-- 
Shannon Hickey
shannon.hickey at sun.com
Swing Team - Sun Microsystems, Inc.
http://java.sun.com/javase/technologies/desktop



More information about the awt-dev mailing list