Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Autorefresh JTable in Background

924 views
Skip to first unread message

Yang Xie

unread,
Mar 29, 2003, 7:20:49 AM3/29/03
to
Hello All:

I have a question here for you guys... This is a multithread app in
Swing.

I have a JTable within a JScrollPane. I have several text boxes so that
I can type in some product data (I have product category associates with
the input data). Each person can input data for any product category,
but is only responsible for One category. There are two things going on
here: a user can manually update the JTable by clicking the 'Add'
button, and then fire up an auto-refresh thread to exam the data in
database and update JTable every 10 seconds. I would imagine that you
need to stop the existing auto-refresh, if there is any, once you click
the 'Add', and then start a new auto-refresh.

The problem that I have is: I can manually update the table without the
auto-refresh involved. The auto-refresh doesn't seem to work. It is not
the JDBC portion, because I could see in debug more data is coming back.
It has to be something related to the Swing's single thread rule or
timer related. All I got was the Jtable with no data showing in it. (I
tried to create my own thread or use a timer, tried repaint(),
fireXXX-events, and all other methods that I could find from internet).
Please shed some lights on this one, what is the procedure that I need
to go thru.


---yxie

Trever Shick

unread,
Mar 30, 2003, 10:39:21 AM3/30/03
to
Well, you should have posted code... but,
what you may need to do is instead of calling any GUI operation in your
second thread, you need to wrap it in a Runnable and submit it to
SwingUtilties.invokeLater...

Any updates to the ui should be happening in this thrad. So if you were
going to change the model from Thread A, you would do:

Runnable r = new Runnable() {
public void run() {
myTable.setModel(newModel);
// or myTable.fireTableDataChanged();
}
};
SwingUtilties.invokeLater(r);

"Yang Xie" <yx...@ziplink.net> wrote in message
news:3E858D44...@ziplink.net...

0 new messages