Class GenericColumnRenderer

All Implemented Interfaces:
AutoResizableTableCellRenderer, ImageObserver, MenuContainer, Serializable, Accessible, SwingConstants, TableCellRenderer
Direct Known Subclasses:
ColumnRenderer

public class GenericColumnRenderer
extends JLabel
implements AutoResizableTableCellRenderer
A Generic AutoResizableTableCellRenderer that formats items based on an input Format or toString(). Background and foreground colors are based on UI manager properties. This class will automatically resize a table's columns if the column requests it.
See Also:
Serialized Form
  • Constructor Details

  • Method Details

    • getTableCellRendererComponent

      public Component getTableCellRendererComponent​(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
      Specified by:
      getTableCellRendererComponent in interface TableCellRenderer
    • setColors

      protected void setColors​(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
      Configure the foreground and background colors for this cell. These colors are determined by getForeground(JTable, Object, boolean, boolean, int, int) and getBackground(JTable, Object, boolean, boolean, int, int).
      Parameters:
      table - The table being rendered.
      value - The value to render.
      isSelected - If this cell is selected.
      hasFocus - If this cell has UI focus.
      row - The current row number.
      column - The column index.
    • getBackground

      protected Color getBackground​(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
      Get the background color of the current cell. This derives the selected color, as well as the striping colors from the properties set in the UIManager.
      • WTable.highlightBackground - The background color for a selected row
      • WTable.background1 - The even numbered row background
      • WTable.background2 - The odd numbered row background
      Parameters:
      table - The table being rendered.
      value - The value to render.
      isSelected - If this cell is selected.
      hasFocus - If this cell has focus.
      row - The current row number.
      column - The current column index.
      Returns:
      A Color to use for this cell's background.
    • getForeground

      protected Color getForeground​(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
      Get the foreground color of the current cell. This derives the color from UIManager properties. It also contains built in special handling for numbers.
      • WTable.foreground - The foreground color
      • WTable.zeroForeground - (numbers only) The color to use for the number 0
      • WTable.positiveForeground - (numbers only) The color to use for positive numbers
      • WTable.negativeForeground - (numbers only) The color to use for negative numbers
      Parameters:
      table - The table being rendered.
      value - The value being rendered.
      isSelected - If the cell is selected.
      hasFocus - If the cell has focus.
      row - The current row number.
      column - The current column index.
      Returns:
      A Color to use for this cell's foreground.
    • getHorizontalAlignment

      protected int getHorizontalAlignment​(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
      Get the horizontal alignment to use for the cell. This defaults to SwingConstants.RIGHT for numbers or SwingConstants.LEFT for everything else.
      Parameters:
      table - The table being rendered.
      value - The value being rendered.
      isSelected - If the cell is selected.
      hasFocus - If the cell has focus.
      row - The current row number.
      column - The current column index.
      Returns:
      The cell's horizontal alignment.
    • getFont

      protected Font getFont​(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
      Get the font for the cell. Defaults to a UIManager property WTable.font.
      Parameters:
      table - The table being rendered.
      value - The value being rendered.
      isSelected - If the cell is selected.
      hasFocus - If the cell has focus.
      row - The current row number.
      column - The current column index.
      Returns:
      The font to use.
    • getText

      protected String getText​(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
      Get the text to display. If no Format was specified at construction time, simply toString() the object. Otherwise, delegated to Format.format(Object)
      Parameters:
      table - The table being rendered.
      value - The value being rendered.
      isSelected - If the cell is selected.
      hasFocus - If the cell has focus.
      row - The current row number.
      column - The current column index.
      Returns:
      The String to render
    • validate

      public void validate()
      Overridden for performance reasons.
      Overrides:
      validate in class Container
    • revalidate

      public void revalidate()
      Overridden for performance reasons.
      Overrides:
      revalidate in class JComponent
    • repaint

      public void repaint​(long tm, int x, int y, int width, int height)
      Overridden for performance reasons.
      Overrides:
      repaint in class JComponent
    • repaint

      public void repaint​(Rectangle r)
      Overridden for performance reasons.
      Overrides:
      repaint in class JComponent
    • firePropertyChange

      protected void firePropertyChange​(String propertyName, Object oldValue, Object newValue)
      Overridden for performance reasons.
      Overrides:
      firePropertyChange in class Component
    • firePropertyChange

      public void firePropertyChange​(String propertyName, boolean oldValue, boolean newValue)
      Overridden for performance reasons.
      Overrides:
      firePropertyChange in class JComponent
    • setAutoResize

      public void setAutoResize​(boolean autoResize)
      Specified by:
      setAutoResize in interface AutoResizableTableCellRenderer
    • isAutoResize

      public boolean isAutoResize()
      Specified by:
      isAutoResize in interface AutoResizableTableCellRenderer
    • shouldApplyNumberFormatting

      protected boolean shouldApplyNumberFormatting​(Object value)
    • getFontDefaults

      protected UIDefaults getFontDefaults()
    • getColorDefaults

      protected UIDefaults getColorDefaults()