I wanna add an image to a button, set a binary attribute stored in the database in that button.
Maybe is a way to do it, there’s not an property in Button.class that can make it, I would appreciate it if you could help me with this
Hello!
Button is intended to be used with small icon that can be placed before the text. Anyway, you can try to use the following code:
myButton.unwrap(JmixButton.class).setIcon(new StreamResource(()
-> new ByteArrayInputStream(myEntity.getFileInBytes()), "some_filename.png"));
If you need just handle a click on image, I can suggsets you to use Image component and click listener.
<data readOnly="true">
<instance id="personDc"
class="ui.ex1.entity.Person">
<fetchPlan extends="_base"/>
<loader/>
</instance>
</data>
<layout spacing="true">
<image id="bytesImage"
dataContainer="personDc"
property="image"/>
</layout>
@Subscribe("bytesImage")
public void onImageClick(Image.ClickEvent event) {
// handle click event
}