/* * Fix for BugTraq ID 4041703. * Set the focus to a reasonable default for an Applet. */ private void setDefaultFocus() { Component toFocus = null; Container parent = getParent(); if (parent != null) { if (parent instanceof Window) { toFocus = getMostRecentFocusOwnerForWindow((Window) parent); if (toFocus == parent || toFocus == null) { toFocus = parent.getFocusTraversalPolicy().getInitialComponent((Window) parent); } } else if (parent.isFocusCycleRoot()) { toFocus = parent.getFocusTraversalPolicy().getDefaultComponent(parent); } } if (toFocus != null) { if (parent instanceof EmbeddedFrame) { ((EmbeddedFrame) parent).synthesizeWindowActivation(true); } // EmbeddedFrame might have focus before the applet was added. // Thus after its activation the most recent focus owner will be // restored. We need the applet's initial focusabled component to // be focused here. toFocus.requestFocusInWindow(); } }