I have been setting values on swing components just like I would any other variable, however I came across this page – https://bitguru.wordpress.com/2007/03/21/will-the-real-swing-single-threading-rule-please-stand-up/ – and it seems that I be making all changes to swing components using an event dispatching thread –
So, is this correct, should I change all the code where I updated swing components from this
String name = this.getNameTextfield().getText();
String password = new String(this.getPasswordField().getPassword());
String confirmPassword = new String(this.getConfirmPasswordField().getPassword());
to this?
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
String name = this.getNameTextfield().getText();
String password = new String(this.getPasswordField().getPassword());
String confirmPassword = new String(this.getConfirmPasswordField().getPassword());
}
});
Is that the standard practise?
Edit: Oops, just copied and pasted some of my component related code, overlooked the fact that it wasnt updating componenets.
In this specific case you do not modify any component, so you don’t need to do it on the EDT, but when you do modify the UI, the second method is correct.