confusedtekguy
IS-IT--Management
Hi all I'm having a problem displaying an array of double into a JTable. The double array ammortize[][] contains 360 rows of 4 columns of mortgage calculations, and I'm looking to display it in JTable, by using a decimal formatter to format the data and save the formated strings in an Object array of Strings so I can display it in a JTable.
My biggest problem is that function where I set the Object array to the formated string does [[]b]not[[]/b] work inside the for loop. It does however work if I take out the for loop and only initilalize the first row and then the table prints first row of numbers. I thought about using vectors, but I'm not sure how to declare and use a 2D vector. Any help would be very much appretiated, I'm new to java and I'm sure there is an easy way of doing this, I just can't figure out what it is.
Code:
int payments_per_year,
interest_payed = 0,
principle_applied = 1,
cum_principle = 2,
new_balance = 3;
NumberFormat numberFormatter;
String temp;
numberFormatter = new
DecimalFormat("'$'#,###,###.##");
String[] columnNames = {
"Payment Number",
"Interest Paid",
"Principle Paid",
"Total Principle Paid",
"New Balance",
};
Object [][] data = new String[360][5];
for(int i=0;i<=10;i++){
temp = Integer.toString(i);
data[i][0]= temp;
temp = numberFormatter.format(amortization[i][interest_payed]);
data[i][1] = temp;
temp = numberFormatter.format(amortization[i][principle_applied]);
data[i][2] = temp;
temp = numberFormatter.format(amortization[i][cum_principle]);
data[i][3] = temp;
temp = numberFormatter.format(amortization[i][new_balance]);
data[i][4] = temp;
}
model = new DefaultTableModel(data, columnNames);
table = new JTable(model);
table.setPreferredScrollableViewportSize(new Dimension(1100, 700));
JScrollPane scrollPane = new JScrollPane(table);
add(scrollPane);
My biggest problem is that function where I set the Object array to the formated string does [[]b]not[[]/b] work inside the for loop. It does however work if I take out the for loop and only initilalize the first row and then the table prints first row of numbers. I thought about using vectors, but I'm not sure how to declare and use a 2D vector. Any help would be very much appretiated, I'm new to java and I'm sure there is an easy way of doing this, I just can't figure out what it is.