Forums Register Login

Table showing same value in all columns

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
That is what your while is telling it to do. The setValueAt calls within the while set 1,0 and 1,1 over and over.
+Pie Number of slices to send: Send
Paul can you elaborate on the problem?
+Pie Number of slices to send: Send

The setValueAt call always sets row 1 columns 0 and 1. Did you mean to use i and not 1? You are incrementing i each time but do not use it.
+Pie Number of slices to send: Send
I see your interpretation, however, since I know that for this test I only have one key/value pair to display (i.e. one row). I just put in the constant of 1 for the row. Still what I get is the Key displayed in the first two columns and NOT the key in column one and the key value value in column two. Hope this clarifies the problem.
Yes, of course, and I accept that blame. In fact, i covet that blame. As does this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 753 times.
Similar Threads
JTable
Swing--JTable in JInternalFrame
jtable
Selecting cells in JTable
JTable
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 11:50:49.