# Close JPopupMenu on Keystroke

**URL:** <https://discourse.processing.org/t/close-jpopupmenu-on-keystroke/23961>\
**Category:** Development\
**Created:** [September 19, 2020, 1:01pm UTC](https://discourse.processing.org/t/close-jpopupmenu-on-keystroke/23961 "2020-09-19T13:01:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Okaghana](https://avatars.discourse-cdn.com/v4/letter/o/dc4da7/32.png) [@Okaghana](https://discourse.processing.org/u/Okaghana)\
**Post date:** [September 19, 2020, 1:01pm UTC](https://discourse.processing.org/t/close-jpopupmenu-on-keystroke/23961/1 "2020-09-19T13:01:05Z")

</div>

Hey Guys. Im creating tool to autocomplete Text for the Processing IDE. The following class Is the popup-menu that pops up to present the different fill-in possibilities:

```auto
class Entry extends JPopupMenu implements KeyListener{

    private JEditTextArea parent;
    
    public Entry(String word, JEditTextArea _parent) {
        super();
        parent = _parent;
        parent.add(this);
        
        parent.addKeyListener(this);
        
        add(word);
    }
    
    public void show(int x, int y) {
        super.show(parent, x, y);
    }
    
    public void keyPressed(KeyEvent key) {
        setVisible(false);
        setEnabled(false);
    }
    
    public void keyReleased(KeyEvent key) {}

    public void keyTyped(KeyEvent key) {}
}

```

The class gets called by the Autocomplete class, which passes the Sting of the typed word and the editor.getTextArea() as an argument.

The problem is, that as soon as the popup opens it blocks the further input of new characters and you have to manually close it by pressing ESC. I tried to make it a KeyListener and make it close on a keystroke, but had no success so far. Is there a way I can make it close on an incoming keystroke?

---

<div class="post-metadata">

**Author:** ![Okaghana](https://avatars.discourse-cdn.com/v4/letter/o/dc4da7/32.png) [@Okaghana](https://discourse.processing.org/u/Okaghana)\
**Post date:** [September 20, 2020, 4:30pm UTC](https://discourse.processing.org/t/close-jpopupmenu-on-keystroke/23961/2 "2020-09-20T16:30:08Z")

</div>

Question has been answered here: [https://stackoverflow.com/questions/63979634/close-jpopupmenu-on-keystroke/63980679#63980679](https://stackoverflow.com/questions/63979634/close-jpopupmenu-on-keystroke/63980679#63980679)
