• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to switch from worker thread to UI thread

 
Mukund Patil
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created the abstract class AbstractConfigPanel wich extends JPanel, in this class constructor created the UI with progressbar,startbtn, textarea etc.

After click on start button, the code do some processing in background , but during that I want to update on UI as well, like if login credentials are correct then print on panel textarea " login success" and then do the remaining backgound execution.

progressbar.setvisible(true);// this is update to UI
int loginCheck = configValidation.validateLogin(userNameTextField.getText(), passwordTextField.getText());
if(loginCheck == 0)
{
infoTextArea.setText("ConfigL10N.LoginSuccess")); // this is update to UI

//background process......
populateData();
panelData.executeOperation();
infoTextArea.setText("");
absButton.setEnabled(false);
}
else
{
infoTextArea.setText("ConfigL10N.LoginFailed")); // this is update to UI
}
progressbar.setvisible(false);// this is update to UI

But the UI updation is done at last..

Please suggest some approach.


Thanks,
Mukund
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1103
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should read the tutorial: Concurrency in Swing
 
Mukund Patil
Greenhorn
Posts: 16
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Implementing SwingWorker, its working fine. Thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!