floating point - jRuby's Float to represent in JTable's cell -


I need to represent Floats in jTable formatted. When I do tbl.model.add_row [obj, 1.3524632478] .to_java , then the OBG is shown as the value instead of the method but does not float. Nothing override float's to_s method I want to have the formatting of spintoff ("% .2f", self) end of the class flat id with the form formatted in all my tables.

I think this is due to the default tableclosure redirector java.lang.float. ToString (some_float) instead of some_float .to_s . Additionally, besides what you've already done with float's two, add them:

  class MyCellRenderer & lt; Java :: JavaxSwingTable :: DefaultTableCellRenderer :: UIResource def setValue (value) setText (value.nil ?? "": Value.to_s) end end my_cell_renderer = MyCellRenderer.new # to set it to global level my_table.setDefaultRenderer (java .lang.Object, my_cell_renderer) # or for this specific column to set to my_table.column_model.getColumn (0) .setCellRenderer (my_cell_renderer)  

Comments