Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

TableSorter problem with double  RSS feed

 
sajjad murtaza
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
i completed my Jtable based project for the stock market and for the sorting purpose i have used TableSorter which sorts the data through the GetClass method inplemented in the table model.

Now my problem is that i have three types of data in my jtable.
1)String (Company Name, Symbol)
2)Double (Ask Price, Bid price)
3)Integer (Bid Volume, Ask Volume)

it was working fine for me until my boss just asked me to add one more decimnal place in the field with Double values.

For example:

if the bid price is 17.70, my jtable is showng it as 17.7 because it stores it as Double. i need to show it as 17.70.

I've already changed it to string but then TableSorter is sorting it as if its string ..


Any Tricky Solution will do..

Sajjad
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the code posted in your last thread the DoubleRenderer class uses a NumberFormat instance with

to show two decimal places for the double values. The values are kept as type Double in the
TableModel but rendered as type String (by the TableCellRenderer) in the table view.
[edit for width]
[ September 09, 2005: Message edited by: Craig Wood ]
 
sajjad murtaza
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply Craig.

as you have mentioned in ur reply that in order to show 2 decimal places, i need to store the value as double and rendered it as a String. i m doing the same way.

Please check out the code of my custom renderer. the constructor is called whenever any update occurs on the data file. it gets the data from the table as string and stores it in a local vector, then my getTableCellRendererComponent checks new values against their counterparts stored in the local vector. i m printing the values on the java console as well, and they are perfect there but not showing in the table.




Thanks,
Sajjad
 
sajjad murtaza
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, i formatted the file for u but forgot to delete some of the class variables that i m not using anymore. Please ignore that.

Sajjad
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you pass the arguments on to 'super' with

the cells text is set without any NumberFormat formatting. In your 'Double' section you call
'setForeground' and 'setFont' on the JLabel (DefaultTableCellRenderer extends JLabel)
Component 'cell' but never 'setText' with the formatted value. So try adding this in each
section, for example
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!