I Have this code which is a part of a larger program that sends emails which contain information about a paricular spreadsheet. The EmailOverdue.run() method is the "slow method" that I'm referring to, since it takes a few seconds to run. After that method runs, the JLabel called status is supposed to say "Sent", which works. What I'm having trouble with is the line where I say status.setText("Sending Message...");
. Instead of saying that, the jlabel just doesn't change until it says sent at the end. How can I make the JLabel update right after I change the text to "Sending Message..." so that it displays that while the "slow" email method is running? My code is below, thanks for the help.
JButton submit = new JButton("Send Email");
submit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
String daysOverFilterString = daysOver.getText();
daysOverFilterString = daysOverFilterString.trim();
sendEmail1 = false;
sendEmail2 = false;
sendEmail3 = false;
//email1, email2, and email3 are checkboxes created earlier
if(email1.isSelected())
sendEmail1= true;
if(email2.isSelected())
sendEmail2= true;
if(email3.isSelected())
sendEmail3= true;
try {
daysOverFilter = Integer.valueOf(daysOverFilterString);
} catch (NumberFormatException nfe) {
status.setText("Please Enter a Numerical Value");
status.setForeground(Color.RED);
intValue = false;
}
if(intValue && (!sendEmail1 && !sendEmail2 && !sendEmail3)) {
status.setText("Please Select At Least One Email Address");
status.setForeground(Color.RED);
checkBoxes = false;
}
if(intValue && checkBoxes) {
status.setText("Sending Message"); //this never actually shows up, which is what I'm tryna fix
status.setForeground(Color.ORANGE);
try {
//EmailOverdue is a seperate class by the way, that sorts through some data and sends an email
EmailOverdue.run(daysOverFilter, sendEmail1, sendEmail2, sendEmail3); //this is the "slow method"
} catch (Exception e) {
e.printStackTrace();
}
}
}
});