Reputation: 95
I would like to add 2 listeners at my JList
: MouseListener
and KeyListener
; and use only MouseClicked
et Keypressed
but at the same class...
I know that I can do:
class FindSuggestionListener implements MouseListener, KeyListener
But it means that I have to do :
myJlist.addMouseListener(new findSuggestionListener());
myJlist.addKeyListener(new findSuggestionListener());
and so, add unimplemented methods...
Do you know how can I implement 2 different listeners at the same class and adding at a swing component?
thank you
Upvotes: 0
Views: 185
Reputation: 601
Make your listener into a variable then add it to the JList
findSuggestionListener suggestionListener = new findSuggestionListener();
myJlist.addMouseListener(suggestionListener);
myJlist.addKeyListener(suggestionListener);
Upvotes: 2