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(); } } }
/** Deregister us as KeyEventDispatcher and property "managingFocus" listeners. */ private void removeTraversingOutListeners(KeyboardFocusManager kfm) { kfm.removeKeyEventDispatcher(this); kfm.removePropertyChangeListener("managingFocus", this); }