Class NumericCellRenderer

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, SwingConstants, TableCellRenderer

public class NumericCellRenderer extends DefaultTableCellRenderer
Provides better rendering of numeric table cells than the default JTable renderer. Single-element primitive arrays are treated just like the corresponding wrapper classes, and the first few elements of a multi-element array are displayed. Numeric values are displayed with decimal points aligned and so on. This class is generally adapted to display of numeric values, but it can render Strings or other Objects too.

Cell rendering can be further refined by extending this class and overriding the setValue(java.lang.Object) method.

Author:
Mark Taylor (Starlink)
See Also:
  • Field Details

    • MAX_SHOW_ELEMENTS

      public static final int MAX_SHOW_ELEMENTS
      The most elements that will be shown in a single cell.
      See Also:
  • Constructor Details

    • NumericCellRenderer

      public NumericCellRenderer(Class<?> clazz)
      Construct a new NumericCellRenderer with a hint about the values it will be expected to render. An attempt will be made to render other objects, but the alignment and so on may not be so good.
      Parameters:
      clazz - the type of object it will expect to render on the whole
  • Method Details

    • setCellFont

      public void setCellFont(Font font)
      Sets the font in which to render cell contents.
      Parameters:
      font - the font to use for text rendering
    • getCellFont

      public Font getCellFont()
      Returns the font in which cell contents will be rendererd.
      Returns:
      the font used for text rendering
    • setValue

      protected void setValue(Object value)
      Sets the state of this renderer, overriding the method in DefaultTableCellRenderer to provide more intelligent behaviour.

      Subclasses note: the work is done by invoking this object's setText and possibly setIcon methods (remember this object is a javax.swing.JLabel).

      Overrides:
      setValue in class DefaultTableCellRenderer
      Parameters:
      value - the value to be rendered
    • setBadValue

      public void setBadValue(Object badValue)
      Sets a value to be regarded as bad when found in a non-header cell. Any cell containing an object which equals() this value will be represented specially in the table body (currently just blank).
      Parameters:
      badValue - the special bad value
    • getCellWidth

      public int getCellWidth()
      Returns the advised width for table cells rendered by this object, on the assumption that the objects it is asked to render are as per the constructor.
      Returns:
      the advised cell width in pixels