Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SWT: missing a MouseListener method

 
manuel aldana
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.
 
Mathias Nilsson
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic