Honestly am writing an application and am stuck at this point.
problem is am writing an asset derpreciation application and i am calculating for Monthly Depreciation,End-of-year value ,Accumulated depreciatio.I want get the results of the values in this form in my jTable when the calculation is done.

for example when i enter the number of months, it should display the results over that number,so if it is 7 it should display as below.

           Monthly            End-of-year       Accumulated
Months   Depreciation          value            depreciation
----     ------------         -----------       ------------
1           4000                24000            4000
2           4000                20000            8000
3           4000                16000            12000
4           4000                12000            16000
5           4000                8000            20000
6           4000                4000             24000
7           4000                 0               28000

how to get this in my jtable is now my headache. I will appreciate the assistance very much thank you

If you check the API doc for JTable you will find a choice of constructors that let you supply the data as a simple 2D array (see the doc for all the options) such as

new JTable(Object[][] rowData, Object[] columnNames);

It won't be hard to put your data into a 2D array of Integers, and the column headings into an array of Strings.

The API doc also has extensive discussion and examples for other ways to populate a table with data.

The Oracle Java Tutorials are an excellent source of info like this - see

  1. create DefaultTableModel for JTable

  2. in DefaultTableModel, there to override

    • public Class<?> getColumnClass(int column) { seems like as there are numbers only, then with Long or Double.Class

    • public boolean isCellEditable(int row, int col) { returns false (non-editable) for column contains sum, result

    • public void setValueAt(Object aValue, int rowIndex, int columnIndex) { there inside you must to call super.setValueAt(aValue, rowIndex, columnIndex); == value enterer by user, then loop inside int rowIndex and to create formula with output to the (undeditable) column contains sum or result, again with super.setValueAt(sum, i, columnIndex);

    • you can to bothering with AbstractTableModel, but I can't found any reason for

    • short cut - is quite easier to search for good code based on AbstractTableModel

    • for mouse and key events over JTable to define JTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

  3. everything about my a.m. points, details, good practiques is quite good described in official Oracle tutorial How to use Tables