changing the image of a draw2d button after creation
-
06-06-2021 - |
Question
I am writing an eclipse plugin using draw2d. I am creating a draw2d button using the constructor : Button(Image image). At some point I want to change the image on that button! I can not find a way of doing it. Can anyone help me please?
Kind Regards, Kyriakos
Solution
You could do the following:
Button button = ...
Image newImage = ...
((Label) button.getChildren().get(0)).setIcon(newImage);
It's certainly not nice, but it seems to be the only option.
OTHER TIPS
Can't be done. The function that sets the image on the button is Clickable.setContents
, which is protected
. There is nothing in the documentation telling why this was done... You can try to inherit from Button
and adding a new function to implement this.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow