In my quest to understand concurrency in Java. I created a program with a GUI that has a JTextArea named display
.
There is also a JButton
that one clicks to open a secondary frame to play with a JProgressBar
(see here).
The ActionListener
for the button that opens the new frame includes this code:
SwingWorker<String, Void> openProgressorGUI =
new SwingWorker<String, Void>() {
@Override
protected String doInBackground() throws Exception {
ProgressorGUI bp = new ProgressorGUI();
bp.setVisible(true);
bp.pack();
return null;
}
};
openProgressorGUI.execute();
display.append("You just opened the Progress Bar window”);
When the button is clicked, the secondary frame opens and does what it needs to, but the display
in the main GUI doesn't print "You just opened the Progress Bar window".
My understanding is that a SwingWorker opens a new background thread so the event dispatch thread is not interrupted.
Why isn't control continuing past the SwingWorker
to finish the code in the ActionListener
?