Is this your first time here? SwingWiki is a Java Swing Developer community site with an big archive of Swing-related usenet groups and mailing lists, but also tips, tricks and articles and book reviews written by your colleagues from around the world. If you came here through a search engine and did not find what you were looking for, make sure to check the wiki table of contents.

There are several cases in which we need to copy content of table renderer component into offscreen image. (e.g. showing “tooltip” which contains full lenght of rendered cell). For doing such a thing follow this code.

         public Image copyImageOfCell(final JTable table, int row, int col) {
                final CellRendererPane cellRendererPane = new CellRenderePane(); //do not always create new cellRenderePane.. recycle usege
                final JComponent renderer = (JComponent) table.prepareRenderer(table.getCellRenderer(row, col), row, col);
                final Dimension rDim = renderer.getPreferredSize();
                final Rectangle rect = table.getCellRect(row, col, true);
                Image image = table.getGraphicsConfiguration().createCompatibleImage(rDim.width, rDim.height);
                Graphics imgGraph = image.getGraphics();
                imgGraph.setClip(new Rectangle(rDim));
                cellRendererPane.paintComponent(imgGraph, renderer, table, 0, 0, rDim.width, rDim.height); 
                return image;

Comments? Corrections? Contact us or Login to edit pages directly (registration is free and takes less than displaying a JLabel)
  howto/copy_image_from_table_renderer.txt · Last modified: 2005/02/18 12:17 by (gojko)
Recent changes | RSS changes | Table of contents | News Archive | Terms And Conditions | Register | The Quest For Software++| Ruby Resources

Sedo - Buy and Sell Domain Names and Websites project info: Statistics for project etracker� web controlling instead of log file analysis