• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need to handle 2 event handlers in one class

 
Colm Dickson
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have a program using one Jlist where if I select the value using the mouse then the related values to the selected item are displayed in another Jlist on the form. This works fine but I noticed that I also need to handle thsi when the up-down keyboard keys are pressed.. I then implemented KeyListener as well as ListSelectionListener with all the required methods and I'm checking up KeyEvent up down etc..and in the keyPressed methods I want to place the same code as in the valueSelected method belonging to the ListSelectionListener interface but it does not have the required effect. before I post my code, can someone advise if I'm doing the right thing or can it be handled a better way?

Thanks,

Colm
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing prevents you from implementing different listeners in the same class. This should be fine.
 
Colm Dickson
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.

Yes I got this working.

In case anyone else wants to know, I added to separated event handlers to my JList. One for KeyListener and another for ListSelectionListener. I then had a class implementing both these interfaces with the code I wanted to fire in the keyPressed and keyReleased methods(implemented as part of the KeyListener interface) and the same code in the valueChanged method belonging to the ListSelectionListener Interface.

Thanks,


Colm
 
Maneesh Godbole
Saloon Keeper
Posts: 11178
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Colm Dickson wrote:
Yes I got this working.


Well done
And thank you for sharing your solution approach for future users.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic