Change Label Image when pressed [message #1494353] |
Mon, 01 December 2014 06:51  |
Eclipse User |
|
|
|
This could be a general question for SWT too, and maybe I've missed something in the event API, but I cannot see it...
I have a Label that acts like a Button - when pressed I capture it and perform some event logic. This is done with a MouseDown event, since Label does not support a Selection event.
OK, but now I want to give my Label an image, and change the image for a 'pressed' alternative image just while pressed, then revert to the original image when unpressed.
I can use the MouseDown event, and inside here change the image to my pressed image, but how do I reliably change it back when the press is released? MouseUp doesn't work reliably because the user might MouseDown on the control, then drag outside the Label and let go, in which case I never get the MouseUp.
I cannot use MouseEnter/MouseExit because these are not supported by RAP (and rightly so).
Is there an alternative where I can achieve this 'different image while pressed' effect?
I'm thinking JavaScript might be the only option, but I'd really rather not, as it seems that there should be an inbuilt way to do this in Java. Perhaps a 'setPressedImage(Image img) method would be good?
Thanks, John
|
|
|
|
|
|
|
|
|
Re: Change Label Image when pressed [message #1495525 is a reply to message #1494422] |
Tue, 02 December 2014 04:28  |
Eclipse User |
|
|
|
Yes, that works reasonably well for RAP.
I'll have to come up with different branches of code for SWT and Tabris, but it is OK for RAP.
For SWT I can rely on MouseEnter/MouseExit/MouseUp/MouseDown, and physically change the bitmap, and for Tabris it probably doesn't make much sense anyway.
Thanks for your suggestions!
|
|
|
Powered by
FUDForum. Page generated in 0.16267 seconds