robli wrote:Wrong - a renderer must never-ever change the state of the caller! Not having the correct size initially is the least of possible problems, at worst you could get nasty loops ...
Using SE 6.
I have a single column JTable that renders it's rows as JPanel components. The preferred size/height of the panel in each row is based on the content of each row. In current version, the renderer is then calling back to the JTable to set the height of the row as each are rendered.
Complete code f.i. http://java.net/projects/swingx/sources/svn/content/trunk/swingx-core/src/main/java/org/jdesktop/swingx/table/TableUtilities.java?rev=4246
TableCellRenderer r = table.getCellRenderer(row, col); Component comp = table.prepareRenderer(r, row, col); int height = comp.getPreferredSize().height; table.setRowHeight(height);
... doesn't want to trigger the JPanel paint however. How would you ordinarily prepareRenderer in the case where a graphics / paint is required ?
BufferedImage buf = new BufferedImage((int)bean.getSize().getWidth(), 5000, BufferedImage.TYPE_INT_RGB); comp.paintAll(buf.createGraphics());