I have an empty table in my model
// This is in global section of class
ResultSetTableModel HLDmodel = new ResultSetTableModel(); // setup a table for High Level Detail
JTable table;
// This is in a GUI Build section
table = new JTable(HLDmodel);
// inner class to define AbstractTableModel
class ResultSetTableModel extends AbstractTableModel {
ResultSetMetaData metadata; // Additional information about the results
int numcols, numrows; // How many rows and columns in the table
String[] columnNames = {};
Object[][] data = {{" "," "}};
public void setValueAt(Object value, int row, int col)
{
data[row][col] = value;
fireTableCellUpdated(row, col);
}
Here I am building the Headers, Columns and Row data after getting my ResultSet back from Query.
public void actionPerformed(ActionEvent e) {
executeQuery();
colNames = getColNames();
setTblHdr();
Map BBtally = tallybyBB(rs); // Get a tally of results and MAP it
Collection entries = BBtally.entrySet();
Iterator it = entries.iterator();
int i=0;
// Put Tally results into table
while(it.hasNext())
{
Map.Entry em = (Map.Entry)it.next();
HLDmodel.setValueAt(em.getKey(),1,0);
HLDmodel.setValueAt(em.getValue(),1,1);
i++;
}
} // actionPerformed
[B] The results showing up in the table is the same value over and over. Does setValueAt() not add the row and column on the fly. If not, what do I need to do different? Right now I only have one row to show, so I don't even know it what I am doing will actually add multiple rows by incrementing the row variable.
Gary
// This is in global section of class
ResultSetTableModel HLDmodel = new ResultSetTableModel(); // setup a table for High Level Detail
JTable table;
// This is in a GUI Build section
table = new JTable(HLDmodel);
// inner class to define AbstractTableModel
class ResultSetTableModel extends AbstractTableModel {
ResultSetMetaData metadata; // Additional information about the results
int numcols, numrows; // How many rows and columns in the table
String[] columnNames = {};
Object[][] data = {{" "," "}};
public void setValueAt(Object value, int row, int col)
{
data[row][col] = value;
fireTableCellUpdated(row, col);
}
Here I am building the Headers, Columns and Row data after getting my ResultSet back from Query.
public void actionPerformed(ActionEvent e) {
executeQuery();
colNames = getColNames();
setTblHdr();
Map BBtally = tallybyBB(rs); // Get a tally of results and MAP it
Collection entries = BBtally.entrySet();
Iterator it = entries.iterator();
int i=0;
// Put Tally results into table
while(it.hasNext())
{
Map.Entry em = (Map.Entry)it.next();
HLDmodel.setValueAt(em.getKey(),1,0);
HLDmodel.setValueAt(em.getValue(),1,1);
i++;
}
} // actionPerformed
[B] The results showing up in the table is the same value over and over. Does setValueAt() not add the row and column on the fly. If not, what do I need to do different? Right now I only have one row to show, so I don't even know it what I am doing will actually add multiple rows by incrementing the row variable.
Gary