Exemple #1
0
  /**
   * Method description
   *
   * @param window
   */
  public static void centerWindow(Window window) {

    Dimension dimension = window.getSize();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (screenSize.width - dimension.width) / 2;
    int y = (screenSize.height - dimension.height) / 2;
    window.setLocation(x, y);
    window.requestFocus();
  }
Exemple #2
0
  public void setVisible(boolean b) {
    KeyboardFocusManager keyboardFocusManager =
        KeyboardFocusManager.getCurrentKeyboardFocusManager();
    if (b) {
      keyboardFocusManager.addKeyEventDispatcher(keyManager);
    } else {
      keyboardFocusManager.removeKeyEventDispatcher(keyManager);
    }
    super.setVisible(b);

    Window owner = getOwner();
    if (owner != null) {
      owner.requestFocus();
      if (lastFocusOwner != null) {
        lastFocusOwner.requestFocusInWindow();
      }
    }
  }