I am fairly new to Java so I am probably missing something fundamental here but here goes.
I have a GUI with a button and I want to click on it, change the text in a window to something then perform a task
connectButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
databaseConnectWindow.setText("Connecting...");
connectToDatabase();
}
});
But with the code above the text in databaseConnectWindow does not change until after conectToDatabse has finished.
Any ideas?
Use a SwingWorker for a background thread so you don’t lock the GUI thread otherwise known as the event dispatch thread or EDT. For more on this, please check out Lesson: Concurrency in Swing