JAL-2987 tolerate null double values when formatting JTable
[jalview.git] / src / jalview / fts / core / DecimalFormatTableCellRenderer.java
index a9e303c..2453742 100644 (file)
@@ -30,8 +30,7 @@ import javax.swing.table.DefaultTableCellRenderer;
 /**
  * The class to handle the formatting of the double values for JTable cells.
  */
-public class DecimalFormatTableCellRenderer extends
-        DefaultTableCellRenderer
+public class DecimalFormatTableCellRenderer extends DefaultTableCellRenderer
 {
   private DecimalFormat formatter;
 
@@ -47,8 +46,8 @@ public class DecimalFormatTableCellRenderer extends
       {
         significantFigureBuilder.append("0");
       }
-      formatter = new DecimalFormat(fractionFormater
-              + significantFigureBuilder.toString());
+      formatter = new DecimalFormat(
+              fractionFormater + significantFigureBuilder.toString());
     }
     else
     {
@@ -62,17 +61,15 @@ public class DecimalFormatTableCellRenderer extends
     super.setHorizontalAlignment(JLabel.RIGHT);
   }
 
+  /**
+   * Adapts the default method to ensure that double values are formatted for
+   * display
+   */
   @Override
-  public Component getTableCellRendererComponent(JTable table,
-          Object value, boolean isSelected, boolean hasFocus, int row,
-          int column)
+  public Component getTableCellRendererComponent(JTable table, Object value,
+          boolean isSelected, boolean hasFocus, int row, int column)
   {
-    if (value == null)
-    {
-      return null;
-    }
-
-    value = formatter.format(value);
+    value = value == null ? "" : formatter.format(value);
 
     return super.getTableCellRendererComponent(table, value, isSelected,
             hasFocus, row, column);