I want to use thread to change the content of JLabel when clicking one button. this button will process one document which cost lots of time. But when I click the button, the content of the JLabel will be showed after processing the document. I want it can be showed immediately.
here is the code
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String command = e.getActionCommand();
// Load button
if (command.equals("Load")) {
// set load to true
load = true;
// get text area name
name = nameField.getText();
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
loadState.setText("Loading document "+name+" . Please wait!");
}
}).start();
// load daffodils
if (name.toLowerCase().equals("daffodils.txt")) {
try {
loadText(tpPoem);
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
anyone can tell me why this thread doesnt work.