Class DecimalRenderer

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

public class DecimalRenderer extends JLabel implements TableCellRenderer
Table cell renderer for a decimal text field.
See Also:
  • Field Details

    • format

      protected DecimalFormat format
      DecimalFormat used as the formatter for the text field.
    • mNumFractionalDigits

      protected int mNumFractionalDigits
      Indicates the number of fractional digits to use on the text field.
    • BIG_ZERO_STRING

      public static final String BIG_ZERO_STRING
      See Also:
    • BIG_DECIMAL_DEFAULT

      public static final BigDecimal BIG_DECIMAL_DEFAULT
    • DEFAULT_ROUNDING_PRECISION

      public static final int DEFAULT_ROUNDING_PRECISION
      See Also:
  • Constructor Details

    • DecimalRenderer

      public DecimalRenderer()
      Construct a DecimalRenderer object.
  • Method Details

    • setNumFractionalDigits

      public void setNumFractionalDigits(int numDigits)
      This method will modify the number of digits allowed after the decimal separator. Once the number of digits is entered, any additional data is ignored.
      The default is 2.
      Parameters:
      the - number of digits allowed after the decimal separator
    • getTableCellRendererComponent

      public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
      Returns the JFormattedTextField component used for drawing the cell. This method is used to configure the renderer appropriately before drawing.
      Specified by:
      getTableCellRendererComponent in interface TableCellRenderer
      Parameters:
      table - the JTable that is asking the renderer to draw; can be null
      value - the value of the cell to be rendered. It is up to the specific renderer to interpret and draw the value.
      isSelected - true if the cell is to be rendered with the selection highlighted; otherwise false
      hasFocus - if true, render cell appropriately. For example, put a special border on the cell, if the cell can be edited, render in the color used to indicate editing
      row - the row index of the cell being drawn. When drawing the header, the value of row is -1
      column - the column index of the cell being drawn
    • setupFormat

      protected void setupFormat(int numDigits)
      Setup the decimal format object for this renderer.
      Parameters:
      numDigits - the number of fractional digits for the format