• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Thread in actionPerformed...

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving this thread to the Swing forum (I think you'll get better results there).
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 2596
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a look at the SwingWorker class, it is very useful.
- Manish
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic