Re: TableModel and ArrayIndexOutOfBounds caused by changing the data while rendering the table
- From: "Oliver Wong" <owong@xxxxxxxxxxxxxx>
- Date: Wed, 12 Jul 2006 19:30:12 GMT
<junk@xxxxxxxxxxxxxxx> wrote in message news:1152729584.407776.167080@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi - my apologies if this has already been covered someplace, but I
couldn't find a reference to the exact problem anywhere in this
newsgroup.
I've created a table model that extends AbstractTableModel. I have a
Vector filled with objects whose properties I want to print in the
table; like so:
public int getRowCount()
{
return myData.size();
}
public Object getValueAt(int row, int col)
{
MyData aData = (MyData)myData.elementAt(row);
switch (col)
{
default:
return aData.toString();
}
}
The problem I'm having is that the Vector is being updated constantly,
and sometimes a row is deleted while the table is being rendered; that
is, between when javax.swing.plaf.basic.BasicTableUI calls
getRowCount() and when it calls getValueAt(), so by the time it calls
getValueAt, the number of rows has changed and Vector.elementAt(int)
throws an ArrayIndexOutOfBoundsException. I've been trying to figure
out how I could "lock" the vector at the start of the table-painting
and "unlock" it at the end, so the delete-row action won't occur until
after it's finished painting, but I haven't had any luck. I'd greatly
appreciate any ideas or solutions.
See http://java.sun.com/docs/books/tutorial/essential/threads/ and especially the section on synchronization.
- Oliver
.
- References:
- Prev by Date: TableModel and ArrayIndexOutOfBounds caused by changing the data while rendering the table
- Next by Date: Re: Exception handler problem.
- Previous by thread: TableModel and ArrayIndexOutOfBounds caused by changing the data while rendering the table
- Next by thread: Re: TableModel and ArrayIndexOutOfBounds caused by changing the data while rendering the table
- Index(es):