Hi everybody!
I have a problem when inserting a new row into the table's model. I want the table to insert new rows at the table's top and display the table's end. This works fine when starting the gui in VisualAge for
Java, but when starting the gui from the console (Java 2 Runtime Environment, build 1.3.0_02, mixed mode) the table flickers when updating the content.
This is how I do the inserting and jumping mechanism (the whole code snippet is triggered by a timer event):
// get the actual data:
Vector tableData = getMyTableModel().getDataVector();
// new data:
MyData data = getNewData();
// insert a new row:
switch (mInsertPosition)
{
case INSERT_AT_START:
tableData.insertElementAt(data, 0);
getMyTableModel().fireTableRowsInserted(0, 0);
break;
case INSERT_AT_END:
default:
getMyTableModel().fireTableRowsInserted(tableData.size() - 1, tableData.size() - 1);
tableData.addElement(data);
}
// jump to the desired position:
switch (mJumpMode)
{
case JUMP_TO_START:
getScrollPane().getViewport().setViewPosition(new Point(0, 0));
break;
case JUMP_TO_END:
JViewport vp = getScrollPane().getViewport();
int vpos = 0;
// height of a single row
int rHeight = getTable().getRowHeight() + getTable().getIntercellSpacing().height;
// total height of the table
vpos = rHeight * getTable().getRowCount();
// subtract the visible height to get the upper left position
vpos = vpos - vp.getExtentSize().height;
if (vpos < 0) vpos = 0;
vp.setView(getTable());
// set the new position
vp.setViewPosition(new java.awt.Point(vp.getViewPosition().x, vpos));
break;
case DONT_JUMP:
default:
if (mInsertPosition == INSERT_AT_START)
{
Point viewPosition = getScrollPane().getViewport().getViewPosition();
// add one row height to the actual position!!!
int rowHeight = getTable().getRowHeight() + getTable().getIntercellSpacing().height;
viewPosition.y += rowHeight;
getScrollPane().getViewport().setViewPosition(viewPosition);
}
else // INSERT_AT_END
{
// do nothing...
}
}
What am I doing wrong? Any help would be appreciated.
Thanks in advance
Thomas