/** A class to render numbers in scientific format. */
  class ScientificRenderer extends JLabel implements TableCellRenderer {
    NumberFormat format = NumberFormat.getInstance();

    public ScientificRenderer(int sigfigs) {
      sigfigs = Math.min(sigfigs, 6);
      if (format instanceof DecimalFormat) {
        String pattern = "0.0"; // $NON-NLS-1$
        for (int i = 0; i < sigfigs - 1; i++) {
          pattern += "0"; // $NON-NLS-1$
        }
        pattern += "E0"; // $NON-NLS-1$
        ((DecimalFormat) format).applyPattern(pattern);
      }
    }

    public Component getTableCellRendererComponent(
        JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
      setFont(
          getDefaultRenderer(String.class)
              .getTableCellRendererComponent(DatasetStatisticsTable.this, "a", false, false, 0, 0)
              .getFont()); //$NON-NLS-1$
      setText(format.format(value));
      setHorizontalAlignment(SwingConstants.TRAILING);
      return this;
    }
  }
Ejemplo n.º 2
0
 public ChefTable() {
   _timeFormat = NumberFormat.getInstance(java.util.Locale.US);
   _timeFormat.setGroupingUsed(false);
   _timeFormat.setMinimumFractionDigits(4);
   _timeFormat.setMaximumFractionDigits(4);
 }