Esempio n. 1
0
  /** @param buttonPanel */
  protected void installFocusHandlers(JPanel buttonPanel) {
    // disable buttons when this "frame" is defocused
    FocusListener focusListener =
        new FocusListener() {
          public void focusGained(FocusEvent e) {
            moveButton.setEnabled(true);
            closeButton.setEnabled(true);
          }

          public void focusLost(FocusEvent e) {
            moveButton.setEnabled(false);
            closeButton.setEnabled(false);
          }
        };
    textarea.addFocusListener(focusListener);
    // have to put the focus listener on every component else it doesn't work every time
    buttonPanel.addFocusListener(focusListener);
    moveButton.addFocusListener(focusListener);
    closeButton.addFocusListener(focusListener);
  }