Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

threads and swing

 
Mike Southgate
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is anyone here using threads within the swing components? I'm using them to try to keep th UI responsive while it goes off to the database. I coded the method below to handle getting all of the data again and populating the table model. It occaisionally thows a index exception in the getvalueat method of the table model when I chage from many rows to few rows.
private void reload() {
Thread reloadThrd = new Thread() {
public void run() {
if (tModel != null) {
tModel.setCriteria(criteria);
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
tModel.fireTableDataChanged();
} //method
});
} //method
}; //inner class
reloadThrd.start();
} //method
When I replace the body without the treading (see below) it seems to work (more testing is required since it's a sporadic error.
if (tModel != null) {
tModel.setCriteria(criteria);
}
tModel.fireTableDataChanged();
Any suggestions other than just don't use threads?
ms
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mike
I think it is a great idea to use threads to keep the system responsive.
However I didnt do that, and I didnt loose any points on my GUI (old assignment though)
Regards, Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic