JAL-4217 catch case when the structure viewer doesn't get added to the desktop window...
authorJames Procter <j.procter@dundee.ac.uk>
Thu, 6 Jul 2023 16:35:17 +0000 (17:35 +0100)
committerJames Procter <j.procter@dundee.ac.uk>
Thu, 6 Jul 2023 16:35:17 +0000 (17:35 +0100)
src/jalview/gui/Desktop.java

index 36d6434..12ff20b 100644 (file)
@@ -1078,7 +1078,36 @@ public class Desktop extends jalview.jbgui.GDesktop
 
     setKeyBindings(frame);
 
-    desktop.add(frame);
+    // Since the latest FlatLaf patch, we occasionally have problems showing structureViewer frames...
+    int tries=3;
+    boolean shown=false;
+    Exception last=null;
+    do
+    {
+      try
+      {
+        desktop.add(frame);
+        shown=true;
+      } catch (IllegalArgumentException iaex)
+      {
+        last=iaex;
+        tries--;
+        jalview.bin.Console.info(
+                "Squashed IllegalArgument Exception (" + tries + " left) for "+frame.getTitle(),
+                iaex);
+        try
+        {
+          Thread.sleep(5);
+        } catch (InterruptedException iex)
+        {
+        }
+        ;
+      }
+    } while (!shown && tries > 0);
+    if (!shown)
+    {
+      jalview.bin.Console.error("Serious Problem whilst showing window "+frame.getTitle(),last);
+    }
 
     windowMenu.add(menuItem);