All Swing components are implemented for access from one thread (event dispatch thread). Thus, there is no protection against concurrent access and simultaneous changes of variables and fields.
If you're lucky, everything works well. But you cannot rely on it, and the same code can have serious problems the next time you run it.
A simple example:
The JLabel drawing procedure contains the following (simplified) code (taken from the BasicLabelUI class):
# assume your label is enabled Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon(); # what happens if another thread calls label.setEnabled(false) at this point? if (icon != null) { icon.paintIcon(c, g, paintIconR.x, paintIconR.y); } if (label.isEnabled()) { paintEnabledText(label, g, clippedText, textX, textY); } else { paintDisabledText(label, g, clippedText, textX, textY); }
For example, if you call setEnabled () from streams other than EDT, you might get a shortcut with the icon turned on, but the colored text is turned off.
source share