This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

SWT: missing a MouseListener method  RSS feed

 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

my aim is to get execute a listener method ONLY when following is happening:
1)a mouse button is pressed on a Button
2)this mouse button is released when it is still over the Button

unfortunately there are only three events for mouses like mouseUp mouseDown.
if i use mouseUp() the event is fired too when i am pressing the button, exiting the button it and release the mouse button.
this is different to usual gui behaviour so i don't wanna have that.

it would be cool if there was something like mouseClickedAndReleased or something...

thnks.
 
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mouseEntered(MouseEvent e) is invoked when the mouse enters a component.
mouseExited(MouseEvent e) is Invoked when the mouse exits a component.

If you set a boolean value on the mouseEntered event and check the value in the mouseUp event. You must reset the value in the mouseExited event.

// Mathias
 
manuel aldana
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, but i think you meant using Swing or AWT. i am using SWT from eclipse framework.

but anyway i found out the solution:

you have to add a widget-listener called MouseTrackListener and implement callback methods mouseEnter, mouseExit respectively.
 
manuel aldana
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, i've got a new problem regarding the same issue.

to achieve my goal (see first post) i added two mouse-listener to my button:



the problem now is:
when i click on the Button and exit the button, the MouseTrackListener callbacks are not called, i.e. means in a way the buttonDown of MouseListener event blocks the MouseTrackListener callbacks.

i think that is because there is just one queue for all events. so it seems that when mouse button is pressed an event or callback blocks the whole UIThread so mouseExit() can not be called.
but it is still weird that the mouseUp callback is called BEFORE the mouseExit() callback, though i exit the button before releasing the button.

so (if i am right with above assumption) how do i start a new thread for a listener?

many thnx.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!