This patch fixes DefaultDesktopManager.activateFrame() so that it
doesn't recurse infinitely. JInternalFrame.setSelected() must not be
called from here, because this calls back to the desktop manager.

2007-01-30  Roman Kennke  <[EMAIL PROTECTED]>

        PR 20577
        * javax/swing/DefaultDesktopManager.java
        (activateFrame): Added a bunch of null checks. Don't call
        JInternalFrame.setSelected() to avoid recursion.

/Roman

Index: javax/swing/DefaultDesktopManager.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/DefaultDesktopManager.java,v
retrieving revision 1.19
diff -u -1 -5 -r1.19 DefaultDesktopManager.java
--- javax/swing/DefaultDesktopManager.java	15 May 2006 11:18:59 -0000	1.19
+++ javax/swing/DefaultDesktopManager.java	30 Jan 2007 15:36:09 -0000
@@ -281,45 +281,59 @@
           }
       }
 
     c.invalidate();
   }
 
   /**
    * This method activates the JInternalFrame by moving it to the front and
    * selecting it.
    *
    * @param frame The JInternalFrame to activate.
    */
   public void activateFrame(JInternalFrame frame)
   {
     JDesktopPane p = frame.getDesktopPane();
-
+    JInternalFrame active = null;
     if (p != null)
-      p.setSelectedFrame(frame);
-    else
+      active = p.getSelectedFrame();
+    if (active == null)
       {
-        try
+        if (p != null)
           {
-            frame.setSelected(true);
+            p.setSelectedFrame(frame);
           }
-        catch (PropertyVetoException e)
+      }
+    else if (active != frame)
+      {
+        if (active.isSelected())
           {
-            // Do nothing if attempt is vetoed.
+            try
+              {
+                active.setSelected(false);
+              }
+            catch (PropertyVetoException ex)
+              {
+                // Not allowed.
+              }
           }
+        if (p != null)
+          {
+            p.setSelectedFrame(frame);
+          }
+        
       }
-
     frame.toFront();
   }
 
   /**
    * This method is called when the JInternalFrame loses focus.
    *
    * @param frame The JInternalFram to deactivate.
    */
   public void deactivateFrame(JInternalFrame frame)
   {
     JDesktopPane p = frame.getDesktopPane();
     if (p != null)
       {
         if (p.getSelectedFrame() == frame)
           p.setSelectedFrame(null);

Reply via email to