This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable - add column with calculated fields

 
Greg Reeder
Ranch Hand
Posts: 99
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone.

I have a JTable which I create by 1st creating an ArrayList with information out of a database and 2nd using that ArrayList to create an Object[][]. Now, I want to use figures in my table to do a few mathamatical operations.

In a little more detail, it is a list of transaction, each transaction a delta balance field (money in or money out). I now want to create an additional column with the balance of the account at the time of that transaction. (Basic checkbook register design). How in the world do I go about doing that?

Thanks in advance;

Greg
 
Rob Spoor
Sheriff
Pie
Posts: 20510
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create your own TableModel implementation. The simple way is to extend DefaultTableModel and override a few methods:
This basically adds one extra column to the columns specified in the constructor. These methods handle this special column, or use the default behaviour for all other columns.
 
Greg Reeder
Ranch Hand
Posts: 99
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh wow. thanks. I will definately give that a try.
 
Greg Reeder
Ranch Hand
Posts: 99
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so very much. I finally got it to work thanks to your help. Now I just have one last question. Is there a way to get the last column to show up as the 2nd column? I will continue to try to find the answer alone, but a push in the right direction is always helpful. Thanks again.
 
Greg Reeder
Ranch Hand
Posts: 99
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Found it myself. Thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic