• Post Reply Bookmark Topic Watch Topic
  • New Topic

JList Event handling  RSS feed

 
Chris Crawford
Ranch Hand
Posts: 116
1
Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yesterday, I requested help on a problem that turned out to be just an oversight on my part. So I'm going to try everybody's patience again with a completely different problem. I did some searches here and on Google and was unable to find anything related to my problem.

I have a JList working perfectly well, but now I want to soup it up. I want to add prefix keys to change the meaning of a selection event. Thus, if the user clicks on an entry in the List, Method #1 is called; if the user holds down the Shift key while clicking on the same entry, Method #2 is called.

It seems simple enough: add an event mask that selects out the bit representing the Shift key, and branch based on that value. Problem: ListSelectionEvents do not include a word including the key masks. Scratch that idea.

Second solution: add a MouseListener to the JList, in addition to the already-existing ListSelectionListener. The MouseListener determines whether the Shift key is down and posts that information for the ListSelectionListener. Problem: the ListSelectionListener executes before the MouseListener, so the MouseListener is too late to help. Scratch that idea.

Third solution, which I don't want to do: replace the ListSelectionListener with hand-wired code inside the MouseListener that replicates the function of the ListSelectionListener. Yuckers! That will be a LOT of work! It's easier to whine about it here!

Fourth solution: play some tricks with Event sequence management that will somehow fix it. Problem: I don't begin to understand the internals of Event handling, and from what I see, it looks like a huge mess.

Does anybody have a better idea?
 
Fred Kleinschmidt
Bartender
Posts: 571
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You do realize that your requirements break the model that users are used to. For example,
   For control+leftbutton, the user expects this to set the anchor point for multiple additional selections without erasing existing selections.

If you insist on changing how lists work, you will need to write and register your own ListSelectionModel.
 
Chris Crawford
Ranch Hand
Posts: 116
1
Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I realize that I'm going off into the weeds with this idea. I decided that it would be prudent to explore other possible strategies, which I'm working on right now. I'm really hoping that I can come up with another way to get around this UI kluge.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!