• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

JTable CellEditor formatting.

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic