Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Difference b/w CellRenderer and CellEditor  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i am confused between CellRenderer and CellEditor in JTable
what is the difeerence with them and where to use it ?
please help me
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bruno Dery
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!