Menu

How to get rid of commas in the numbers

2005-03-09
2013-04-24
  • Nobody/Anonymous

    Hello all,

    does anyone know how to remove the commas in the Number columns.

    e.g. by default the numbers appear as 150,409 whereas I want them to appear as 150409.

    Thanks,
    Amit

     
    • Nobody/Anonymous

      You can override the default cell renderer for that column. If you have multiple columns that display numbers and you want the same behaviour for all the columns you can use the setDefaultRenderer function to override the renderer for all columns that display numbers.

      yourTable.setDefaultRenderer(Number.class, "your renderer class");

      -Prasanth.

       
    • Nobody/Anonymous

      Hello Prasanth,

      once again thanks for such a prompt reply. I must say this API is very useful.

      Can you explain me where does the comma come into the table. I have used the JTable before and it does not insert comma into the table by itself. I tried to look for something in the SSDataGrid class which is direct subclass of JTable and could not find any logic or reason for it.

      Also, I am using a TableSorter given by the sun
      JTable table = (JTable) viewport.getView();
                  //Encapsulate the table model by TableSorter to add sorting functionality       
                  TableSorter sorter = new TableSorter(table.getModel());
                  table.setModel(sorter);
                  sorter.setTableHeader(table.getTableHeader());

      Is the additional comma due to the TableSorter,
      the code for the table sorter can be found at http://java.sun.com/docs/books/tutorial/uiswing/components/example-1dot4/TableSorter.java

      Prashanth, I would like to recommed the developer to make this small change in API to make the tables sortable.

      Thanks,
      Amit

       
    • Prasanth Pasala

      Prasanth Pasala - 2005-03-09

      The comma is inserted by JTable itself.  NumberFormat is used as a formatter in JTable for double column types. It is not used for Number type columns (meaning numbers other than doubles may not be having the commas, I am guessing based on JTable code)

      We will surely look into adding the sorter for SSDataGrid.

      -Prasanth.

       
    • Nobody/Anonymous

      Thanks,

      Your suggestion worked I have added the CustomRenderer to my class and it works fine.

      Thanks for Helping and sharing your expertisie

      Amit

       

Log in to post a comment.

MongoDB Logo MongoDB