I’m trying to make a login screen for an application. During the login, many SQL calls will be made to a MySQL database, and it may take a few seconds to set everything up. I’d like to display a status screen via Card Layout and update a JLabel while the background thread is running.
Here’s the gist of what I have for my Worker Thread:
public class LoginPrepThread extends Thread {
private final UIMain parent;
public LoginPrepThread(UIMain w){
parent = w;
}
public void exec(){
EventQueue.invokeLater(this);
}
public void run(){
try{
//SqlHelper sql = SqlHelper.instance;
sleep(500);
parent.getLoadingLable().setText("Fetching preferences...");
parent.getMainFrame().revalidate();
sleep(500);
parent.getLoadingLable().setText("Scanning workbench...");
parent.getMainFrame().revalidate();
sleep(500);
parent.getLoadingLable().setText("Updating permissions...");
parent.getMainFrame().revalidate();
sleep(500);
parent.getLoadingLable().setText("Finished...Please wait");
parent.getMainFrame().revalidate();
sleep(1000);
parent.getLayout().show(parent.getMainFrame().getContentPane(), "view.main");
}catch(Exception e){
}
}
}
Here is how I am calling it (Inside the event of a JButton, after authenticating):
setActiveProfile(user);
layout.show(frame.getContentPane(), "view.loading");
frame.repaint();
LoginPrepThread pt = new LoginPrepThread(thisTrick);
pt.exec();
I put some dummy events in for now, but the status label doesn’t change…any suggestions?
A simple swing worker solved it. I guess I wasn’t good enough on my google’ing