Are there alternatives to AWT for getting mouse press events in Java?
-
Is it just curiosity or you are having issues with AWT events? – BackSlash Jun 03 '15 at 12:12
-
eclipse rcp, swings, etc. – Rahul Thachilath Jun 03 '15 at 12:38
-
Yes it appears on Windows 7 AWT mousePressed events are delayed by 5 seconds (or until you release) when using a touch screen device. I need to be able to hold buttons down and have yet to find a way to do this. – user3469157 Jun 03 '15 at 16:22
-
Have you considered JavaFX? It is a better option for touch screen devices, or do you absolutely have to use AWT? – AlmasB Jun 03 '15 at 16:34
-
Absolutely have to use Swing – user3469157 Jun 03 '15 at 18:20
2 Answers
Mouse event implies there's a window / frame on which the event occurred. Typically each GUI toolkit comes with its own list of event listeners / dispatchers. So the question should really be: "What are the alternatives to AWT?"
- There's Swing. You can read about the difference between AWT and Swing here . (The answer also mentions SWT:
Finally, you might also want to check out SWT (the GUI toolkit used for Eclipse, and an alternative to both AWT and Swing), which is somewhat of a return to the AWT idea of accessing native Widgets through Java.
- There's JavaFX, which is a more rich graphics framework and somewhat a successor of Swing. You can read about it on official Oracle JavaFX page here .
If we are talking about specific frameworks then (as far as I know they still use AWT event system underneath):
JMonkey game engine. Official Page
LWJGL. Light weight java gaming library. Official Page
There are probably other frameworks but it seems the core functionality comes from AWT to handle native mouse query.
-
-
I have a Swing GUI but AWT mousePressed events are failing me so looking to see if there is another toolkit I could use to get those events for the swing GUI rather than AWT. – user3469157 Jun 03 '15 at 16:27
Since I found lots of unanswered threads on this I'll share the solution. Turns out Windows 7 defaults Java to wm_gesture rather than wm_touch events so AWT does not get press events as expected. What you need to do is use JNA to register the window as a touch window (https://msdn.microsoft.com/en-us/library/windows/desktop/dd317326(v=vs.85).aspx).

- 129
- 2
- 8