import com.zfqjava.swing.JBean; import com.zfqjava.swing.JDataGrid; import com.zfqjava.swing.JDataGridBean; import com.zfqjava.swing.cell.NumberCellRenderer; import java.text.NumberFormat; import javax.swing.SwingUtilities; /* * FormatDemo.java * * Created on 2007Äê3ÔÂ27ÈÕ, ÉÏÎç8:31 * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ /** * * @author Fuqiang Zhao */ public class FormatDemo extends JDataGridBean { /** Creates a new instance of FormatDemo */ public FormatDemo() { configure(); } private void configure() { final JDataGrid dataGrid = getDataGrid(); NumberCellRenderer renderer = (NumberCellRenderer)dataGrid.getCellManager().getCellRenderer(Number.class); NumberFormat format = NumberFormat.getInstance(); format.setGroupingUsed(false); format.setMinimumFractionDigits(2); format.setMaximumFractionDigits(2); renderer.setDefaultFormat(format); dataGrid.setValueAt("Enable two fraction digits globally", 0, 0); dataGrid.setValueAt(new Double(32.12345), 3, 3); dataGrid.setCellClass(Number.class, 3, 3); } public static void main(String[] args) { final FormatDemo demo = new FormatDemo(); demo.setDefaultCloseOperation(JBean.EXIT_ON_CLOSE); SwingUtilities.invokeLater(new Runnable() { public void run() { demo.showFrame(); demo.getDataGrid().requestFocus(); } }); } }