Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala MouseEvent - How to know which button was pressed?

I'm writing a scala application using scala swing. I can listen for MouseClicked to get notified whenever the mouse is clicked, but how do i know which button was pressed. The documentation is pretty bad, so i have looked in the Java documentation for MouseEvent, which says that the key can be retrieved from the modifiers field, so i tried to output the modifiers field of the scala MouseClicked event, which turned out to be an integer, 0 for left click, mouse button 3 and mouse button 4 and 256 for right click.

It looks like it will work if i only need to know the difference between left and right click, but can i be sure the modifiers all ways work this way? The documentation says nothing, and for what i know modifiers could be affected by other things than just which mouse button was pressed. I would also like to know the difference between left click and mouse button 3 and 4. I don't think users expect them to do the same thing as left click.

In the scala documentation there is a MouseButtonEvent, can this be used for anything? The documentation says nothing about what it does.

like image 984
Andreas Vinter-Hviid Avatar asked Sep 13 '10 13:09

Andreas Vinter-Hviid


1 Answers

You can always use x.peer.getButton to get the Java mapping (where x is your Scala MouseClicked event). peer almost always contains a Java equivalent to the Scala class--and it does in this case.

like image 74
Rex Kerr Avatar answered Oct 18 '22 13:10

Rex Kerr