I have the following code in a method: getComponent(0).removeKeyListener(popupListener); ListenerPerk popupListener = new ListenerPerk(pLabels, this); getComponent(0).addKeyListener(popupListener);
getComponent(0) gives me a valid component. This method does not seem to be removing my listeners. Everytime I call this method I should end up with one KeyListener??? Instead, I end up with several depending on how many times the method is called. Why isn't removeKeyListener() working?
Hi Paul, Not sure what you are doing wrong, but RemoveKeyListener works. Check out the example below. How to run it: 1. Press change button first 2. Click inside anywhere not on button 3. Hit any key and see print 4. Press change button 5. Click inside anywhere not on button 6. Hit any key and see print If you comment out the RemoveKeyListener you will see multiple prints for each key stroke.