- // Figure out the thickness of borders and use that to set the final
- // size.
- if (frame != null) {
- Insets insets = getInsets();
- frame.setSize(width + insets.left + insets.right,
- height + insets.top + insets.bottom);
- } else {
- Insets insets = getInsets();
- component.setSize(width + insets.left + insets.right,
- height + insets.top + insets.bottom);
+ if (SwingUtilities.isEventDispatchThread()) {
+ // We are in the Swing thread and can safely set the size.
+
+ // Figure out the thickness of borders and use that to set the
+ // final size.
+ if (frame != null) {
+ Insets insets = getInsets();
+ frame.setSize(width + insets.left + insets.right,
+ height + insets.top + insets.bottom);
+ } else {
+ Insets insets = getInsets();
+ component.setSize(width + insets.left + insets.right,
+ height + insets.top + insets.bottom);
+ }
+ return;