aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JTable - add column with calculated fields Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable - add column with calculated fields" Watch "JTable - add column with calculated fields" New topic
Author

JTable - add column with calculated fields

Greg Reeder
Ranch Hand

Joined: Jun 14, 2011
Posts: 99

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

Joined: Oct 27, 2005
Posts: 19760
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Greg Reeder
Ranch Hand

Joined: Jun 14, 2011
Posts: 99

oh wow. thanks. I will definately give that a try.
Greg Reeder
Ranch Hand

Joined: Jun 14, 2011
Posts: 99

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

Joined: Jun 14, 2011
Posts: 99

Found it myself. Thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTable - add column with calculated fields