Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Table showing same value in all columns  RSS feed

 
Gary Frick
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gary Frick
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul can you elaborate on the problem?
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Gary Frick
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!