[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.technology.albireo] Re: CTRL-C stack overflow

The choice of JApplet was made rather late, relative to the article's release. I wanted to think it through before making the change. In particular, if the AWT frame gets focus, will it always delegate to the JApplet's focus policy?

If you are running in JDK 1.5+, I believe you could have also solved the problem by calling setFocusTraversalPolicyProvider(false) on the JApplet, leaving the focus traversal policy on the frame. This call is now necessary to truly turn off the JApplet's own default focus handling. This is a new API in 1.5. My testing was largely with JDK 1.4 at the time, so this call was not necessary and not available.

James Peltzer wrote:
I have noticed an interesting problem when you are using a Swing editor.
In a text field in the editor, hit CTRL-C.  Open another editor.  Watch the
stack overflow errors pile up.

Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError
 at java.util.Arrays.mergeSort(Arrays.java:1270)
 at java.util.Arrays.sort(Arrays.java:1210)
 at java.util.Collections.sort(Collections.java:159)
 at
javax.swing.SortingFocusTraversalPolicy.enumerateAndSortCycle(SortingFocusTr
aversalPolicy.java:119)
 at
javax.swing.SortingFocusTraversalPolicy.getFirstComponent(SortingFocusTraver
salPolicy.java:434)
 at
javax.swing.LayoutFocusTraversalPolicy.getFirstComponent(LayoutFocusTraversa
lPolicy.java:148)
 at
javax.swing.DefaultFocusManager.getFirstComponent(DefaultFocusManager.java:9
9)
 at
javax.swing.LegacyGlueFocusTraversalPolicy.getFirstComponent(LegacyGlueFocus
TraversalPolicy.java:115)
 at
javax.swing.LegacyGlueFocusTraversalPolicy.getDefaultComponent(LegacyGlueFoc
usTraversalPolicy.java:133)
 at
javax.swing.SortingFocusTraversalPolicy.getFirstComponent(SortingFocusTraver
salPolicy.java:447)
 ...

I was able to fix this by moving the focus policy from the frame down to the
JApplet.  I notice your article code says to 'consider' this in its
comments, is there any reason why you didn't do it?

-James

Modified code (inside addRootPaneContainer):
        ...
        JApplet applet = new JApplet();

        // In JRE 1.4, the JApplet makes itself a focus cycle root. This
        // interferes with the focus handling installed on the parent frame,
so
        // change it back to a non-root here.
        // TODO: consider moving the focus policy from the Frame down to the
JApplet

        EmbeddedChildFocusTraversalPolicy policy = new
EmbeddedChildFocusTraversalPolicy(awtHandler);
        applet.setFocusTraversalPolicy(policy);
        frame.add(applet);

        return applet;