In my Java Swing application I have the following code that is called when a button is clicked:
class MyWorker extends SwingWorker<String, Object> {
@Override
protected String doInBackground() throws Exception {
loadMasterFile();
judgeFileListModel = new DefaultListModel();
// Refresh model
return "Done.";
}
@Override
protected void done() {
LB.setVisible(false);
}
}
new MyWorker().execute();
In the called code I open a JFileChooser. The first time it runs great - If I then press the button again after the code has finished it hangs. If I then debug and pause when that happens I appear to have a deadlock.
I have no clue how to handle this - still a student.
I'd absolutely love some help if possible.
EDIT:
I've fixed it!
To anyone having a similar issue - it's due to the JFileChooser being inside the loadMasterFile() method. It apparently violates swing rules having any GUI code inside doInBackground() so I refactored it out of there and it works great.