This week's book giveaway is in the Java 9 forum.
We're giving away four copies of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications and have Sander Mak & Paul Bakker on-line!
See this thread for details.
Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

threads and swing  RSS feed

 
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
Posts: 12148
255
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
Boost this thread!