Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread in actionPerformed...  RSS feed

 
Greg Schultz
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created, my First, Swing/AWT application. It does a search through jar and zip files looking for a class. My problem is this. I am passing a reference to two textareas to the search class. The search class is updating the left and right textarea's but they are not being refreshed until the entire search has completed. I think this is because I am performing the search outside of the actionPerformed, but I'm not sure how to go about fixing the problem. The actionPerformed method is listed below..

void jButton_Search_actionPerformed(ActionEvent e) {
String[] args = new String[3];
args[0] = "-a";
args[1] = jTextPath.getText();
args[2] = jTextPattern.getText();
int i = jComboBox_SearchType.getSelectedIndex();
switch (i) {
case 0:
args[0] = "-a";
args[1] = jTextPath.getText();
break;
case 1:
args[0] = "-c";
args[1] = jTextPath.getText();
break;
case 2:
args[0] = "-s";
args[1] = jTextPath.getText();
break;
case 3:
args[0] = "-d";
args[1] = jTextPath.getText();
break;
}
System.out.println(args[0]);
System.out.println(args[1]);
System.out.println(args[2]);
jTextArea_Search.append("\nStarting ZipSearch...\n");
JZSearch js = new JZSearch();
js.doZipSearch(args, jTextArea_Search, jTextArea_Found);
jTextArea_Search.append("\nCompleted ZipSearch...\n");
}

Do I need to use a thread for the call to JZSearch?
TIA,
Greg
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this thread to the Swing forum (I think you'll get better results there).
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Do I need to use a thread for the call to JZSearch?

Yes, absolutely. You can't perform long-running actions in an event handler without preventing normal painting and further event handling from occurring.
 
Manish Hatwalne
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at the SwingWorker class, it is very useful.
- Manish
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!