code: public static void setInitialFocus(Window window, final Component comp){
          window.addWindowFocusListener(new WindowAdapter(){
              @Override
              public void windowGainedFocus(WindowEvent we){
                  comp.requestFocusInWindow();
                  we.getWindow().removeWindowFocusListener(this);
              }
          });
      }
docs: sets intial focus in window to the specified component
  
  @param window    window on which focus has to be set
  @param comp      component which need to have initial focus