1 43 44 package org.jfree.ui; 45 46 import java.awt.Component ; 47 import java.text.NumberFormat ; 48 49 import javax.swing.JTable ; 50 import javax.swing.SwingConstants ; 51 import javax.swing.table.DefaultTableCellRenderer ; 52 53 58 public class NumberCellRenderer extends DefaultTableCellRenderer { 59 60 64 public NumberCellRenderer() { 65 super(); 66 setHorizontalAlignment(SwingConstants.RIGHT); 67 } 68 69 83 public Component getTableCellRendererComponent(final JTable table, 84 final Object value, final boolean isSelected, 85 final boolean hasFocus, final int row, final int column) { 86 87 setFont(null); 88 final NumberFormat nf = NumberFormat.getNumberInstance(); 89 if (value != null) { 90 setText(nf.format(value)); 91 } 92 else { 93 setText(""); 94 } 95 if (isSelected) { 96 setBackground(table.getSelectionBackground()); 97 } 98 else { 99 setBackground(null); 100 } 101 return this; 102 } 103 104 } 105 | Popular Tags |