A cell renderer is used to render the cell in the table, i.e. this is what actually paints what you see in the table. The cell editor on the other hand is used to actually edit the contents of the cell. So you could write a cell editor that knows how to edit the the value in a particular cell and then a painter that nows how to paint it, maybe with an icon or something. This enables you to write editors and painters for you own custom classes so that they can be displayed in the table etc. Hope that helps
Most of the CellEditors (the default ones at least) will be a widget with which you can enter text or select something, for example a JTextField, JCombo or JCheckBox. On the other hand, CellRenderers are the ones used by swing to only display what has been entered previously, so in this case it's usually a JLabel. Think of it as the CellEditor is usually what's used to edit a certain field, and the renderer is used to display ALL fields. The editor will only be displayed when you are in editing mode, meaning when you start typing something in a jtable's cell for example. In all other cases, the renderer is what's used for displaying.
posted 16 years ago
To give a short example, let's say you have a column in your jtable that is for choosing a color. Obviously you will want another way of selecting your color than having to type the text in the table cell (using the default cell editor which is a JTextField), so most likely we would have something like a color chooser for the Editor, or maybe a JCombo to at least select from a given set of colors. That's the editor. Then, it would be nice to display these colors that were entered in all the cells for the color column, so instead of just having the name, you could have the name and a small box painted in the selected color to be more visual. For that, you would need to provide a custom CellRenderer. That's the renderer.
It's a pleasure to see superheros taking such an interest in science. And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop