• Post Reply Bookmark Topic Watch Topic
  • New Topic

AbstractTableModel  RSS feed

 
Evan Gershkovich
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

so I am trying to make the switch from arrays to vectors for my abstracttablemodel and i'm having an issue.

So for one method:

public Object getValueAt(int row, int col)
{
return data[row][col]; => (String[][] data;)
}

I made this change:

public Object getValueAt(int row, int col)
{
Vector rowArray = data.get(row-1);
Object cell = rowArray.get(col-1);
return cell;
}

However, I'm having trouble changing my printDebugData() method:

In the old version it is:

public void printDebugData()
{
int numRows = getRowCount();
int numCols = getColumnCount();

for (int i = 0; i < numRows; i++)
{
logger.info(" row " + i + ":");
for (int j = 0; j < numCols; j++)
{
logger.info(" " + data[i][j]);
}
}
logger.info("--------------------------");
}

If I could get some help I'd truly appreciate it.

Thanks!
 
Rob Spoor
Sheriff
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags next time.

I take it you have problems accessing the single elements? The solution is pretty simple:

1) Use getValueAt:
The advantage of using this technique is that this method will work, no matter how you implement the getRowCount, getColumnCount and getValueAt methods.

2) Use the Vectors in a way similar to getValueAt:

3) Use the for-each loop:


As for the getValueAt method, you are aware that both TableModel and Vector use 0 as starting index?
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!