Change Label Image when pressed [message #1494353] |
Mon, 01 December 2014 11:51 |
|
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
---
Just because you can doesn't mean you should
|
|
|
|
Re: Change Label Image when pressed [message #1494384 is a reply to message #1494363] |
Mon, 01 December 2014 12:28 |
|
Good idea, but unfortunately the MouseUp on the display is not getting triggered.
...
display.addFilter(SWT.MouseUp, ...
...
Also tried display.addListener(SWT.MouseUp, ... but that didn't fire either.
Is there something special that I have to do to get this to fire?
---
Just because you can doesn't mean you should
|
|
|
Re: Change Label Image when pressed [message #1494386 is a reply to message #1494384] |
Mon, 01 December 2014 12:30 |
|
just noticed in the JavaDoc for AddFilter: "NOTE: In RAP, only events that have a matching listener registered on the event's source widget are processed on the server"
is this my problem? I have a MouseDown listener on the Label, but not a MouseUp...?
---
Just because you can doesn't mean you should
|
|
|
|
|
Re: Change Label Image when pressed [message #1494422 is a reply to message #1494400] |
Mon, 01 December 2014 13:06 |
|
Thanks Ivan, I'll have a play around with that idea. I'm not sure that it gives me exactly what I want, but it may be sufficient. I was hoping for a generic solution for SWT and RAP but I don't see that happening.
The CSS theme approach will enable me to at least cause the button to change appearance when pressed, but I don't think I can really use the image attributes because the image needs to be configurable at runtime - the developer may wish to change the image on the fly. However, the primary concern was that the control didn't change appearance at all when pressed, so there was no visual feedback, so using an offset and playing with the border might be an acceptable solution...
time to play...
---
Just because you can doesn't mean you should
|
|
|
Re: Change Label Image when pressed [message #1495525 is a reply to message #1494422] |
Tue, 02 December 2014 09:28 |
|
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!
---
Just because you can doesn't mean you should
|
|
|
Powered by
FUDForum. Page generated in 0.04234 seconds