I have a JTable with very large font in it. I am trying to format the text in a cell editor to match the rest of the table. Looking at Sun's web page for CellEditor http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/CellEditor.html makes me think that it just does not support formatting features, so I am thinking that I need to make something fit over the cell (like a JTextField) that has the ability to setFont. Is this the easy, or right way to do this?
Looking at Sun's web page for CellEditor ... makes me think that it just does not support formatting features CellEditor is a general interface. CellEditor is implemented by AbstractCellEditor which you can use to build a custom cell editor for a JTable. DefaultCellEditor extends AbstractCellEditor and provides more opportunity for formatting control. so I am thinking that I need to make something fit over the cell (like a JTextField) that has the ability to setFont. Is this the easy, or right way to do this? Yes. The general idea is to make an editor and configure it just like your cell renderer is configured so that when it appears during an editing session it looks the same as the renderer. DefaultCellEditor has a constructor that takes a JTextField. To use the default renderer and provide a minimally customized editor to match you could try something like this:
You can get more fancy by providing your own renderer and editor. The renderer is pretty easy to make; often you can extend DefaultTableCellRenderer. The editor is a little more work. You can extend AbstractCellEditor, implement TableCellEditor and provide a configurable member variable component to return as the cellEditor. If you need to implement some of the CellEditor methods you can get some ideas by looking at the DefaultCellEditor source code.
Why should I lose weight? They make bigger overalls. And they sure don't make overalls for tiny ads:
Free, earth friendly heat - from the CodeRanch trailboss