Hi, Yuan Bing,
If you want to always show the last row of a JTable in the
JScrollPane.
You can try the scrollRectToVisible() method in the JTable class.
It goes like this ...
//assume the name of the JTable is "table".
// first cell last row. check for empty table if
necessary.
Rectangle rect = table.getCellRect(table.getRowCount()-1, 0,
yes);
// I believe this will fire the proper event to scroll the
viewport.
table.scrollRectToVisible(rect);
If you are calling this routine from a non GUI thread, you may
want
to wrap it in a SwingUtilities.invokeLater(). I never tried it myself
though.
Have a nice hoiliday,
Song Mingjian
-----Original Message-----
From: Yuan Bing,BISC TD DPC1(BJ) [mailto:[EMAIL PROTECTED]]
Sent: Sunday, December 22, 2002 10:19 PM
To: '[EMAIL PROTECTED]'
Subject: Update the JScrollPane in another threadHi,I want to update the JScrollPane in another thread, like this:------------------------------------------public void newMessage(ChargedCdr ccdr) { // will be invoked in a non-event-dispatching thread...
model.fireTableDataChanged(); //of a table within jScrollPane1
jScrollPane1.getVerticalScrollBar().setValue(jScrollPane1.getVerticalScrollBar().getMaximum());
}
------------------------------------------The function I wanna get is to move the scroll bar to the end of the table whenever model's data changed(by another thread), and it could work, but some times just not to the end of the table, but still has 1 line left below.Maybe I misused the setValue, because it was not in a event-dispatching thread, am I right?Then what is the right way to do this?regards,Yuan Bing
