KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager ();  Window focusedWindow = manager.getFocusedWindow ();  if (isDisplayable () && isShowing () && isFocusable ()) { if (focusedWindow != null) { synchronized (getTreeLock ()) { Container parent = getParent ();  while (parent != null && !(parent instanceof Window)) parent = parent.getParent ();  Window toplevel = (Window) parent;   if (focusedWindow == toplevel) { if (peer != null && !isLightweight() && !(this instanceof Window))    peer.requestFocus (); else {    EventQueue eq = Toolkit.getDefaultToolkit ().getSystemEventQueue (); synchronized (eq) { Component currentFocusOwner = manager.getGlobalPermanentFocusOwner (); if (currentFocusOwner != null) { eq.postEvent (new FocusEvent(currentFocusOwner, FocusEvent.FOCUS_LOST, temporary, this)); eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, temporary, currentFocusOwner)); } else eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, temporary)); } } } else return false; } }  return true;
return requestFocusInWindow (false);
  protected boolean requestFocusInWindow (boolean temporary)  {    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager ();    Window focusedWindow = manager.getFocusedWindow ();    if (isDisplayable ()	&& isShowing ()	&& isFocusable ())      {        if (focusedWindow != null)          {            synchronized (getTreeLock ())              {                Container parent = getParent ();                while (parent != null                       && !(parent instanceof Window))                  parent = parent.getParent ();                Window toplevel = (Window) parent;                // Check if top-level ancestor is currently focused window.                if (focusedWindow == toplevel)                  {                    if (peer != null                        && !isLightweight()                        && !(this instanceof Window))                      // This call will cause a FOCUS_GAINED event to be                      // posted to the system event queue if the native                      // windowing system grants the focus request.                      peer.requestFocus ();                    else                      {                        // Either our peer hasn't been created yet or we're a                        // lightweight component.  In either case we want to                        // post a FOCUS_GAINED event.                        EventQueue eq = Toolkit.getDefaultToolkit ().getSystemEventQueue ();                        synchronized (eq)                          {                            Component currentFocusOwner = manager.getGlobalPermanentFocusOwner ();                            if (currentFocusOwner != null)                              {                                eq.postEvent (new FocusEvent(currentFocusOwner, FocusEvent.FOCUS_LOST,                                                             temporary, this));                                eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, temporary,                                                             currentFocusOwner));                              }                            else                        eq.postEvent (new FocusEvent(this, FocusEvent.FOCUS_GAINED, temporary));                      }                  }                  }                else                  return false;              }          }		return true;	}    return false;  }