So I've got this jtable set up that displays the contents of an arraylist by use of the handy dandy table model (see code below). you'll notice it calls a method makeTableArray() (see code below) in order to figure out what the array that its going to use is. In another part of the program I enter data into this form I made, and it inserts another object in the to the arraylist I was using in the table model. I was wondering, how do I get the table to "refresh" after I submit this new information into the arraylist. I submit the information via a button. Any help is greatly appreciated. I'm using NetBeans IDE 5.5
Table model:
runDisplay.setModel(
new javax.swing.table.DefaultTableModel(
makeTableArray(),
new String [] {
"Date", "Distance (Miles)", "Run Time (hh:mm:ss)", "Run Time (Minutes)", "Avg. Time (Min/Mile)", "Route", "Conditions", "Notes"
}
) {
Class[] types = new Class [] {
java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
});
makeTablearray() method:
private Object[][] makeTableArray(){
ArrayList tempLog = log1.getLog();
Object table[][] = new Object[tempLog.size()][8];
//dates
for(int i = 0; i < tempLog.size(); i++){
table[i][0] = ((Run)tempLog.get(i)).getDate().toString();
}
//distance
for(int i = 0; i < tempLog.size(); i++){
table[i][1] = "" + ((Run)tempLog.get(i)).getDist();
}
//time HMS
for(int i = 0; i < tempLog.size(); i++){
table[i][2] = ((Run)tempLog.get(i)).getTime().toString();
}
//time in Min
for(int i = 0; i < tempLog.size(); i++){
table[i][3] = "" + ((Run)tempLog.get(i)).getTime().getMinTime();
}
//min per mile
for(int i = 0; i < tempLog.size(); i++){
table[i][4] = "" + (((Run)tempLog.get(i)).getTime().getMinTime())/(((Run)tempLog.get(i)).getDist());
}
//route
for(int i = 0; i < tempLog.size(); i++){
table[i][5] = ((Run)tempLog.get(i)).getRoute();
}
//conditions
for(int i = 0; i < tempLog.size(); i++){
table[i][6] = ((Run)tempLog.get(i)).getCon();
}
//notes
for(int i = 0; i < tempLog.size(); i++){
table[i][7] = ((Run)tempLog.get(i)).getNotes();
}
return table;
}