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

有帮助吗?

解决方案

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.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top