got the code below to download a file. It looks kind of strange, does anyone has an idea of how to get this easier/more optically nicer?
Without anchor the download does not work an witout Text in Anchor it also does not download. Would like to have a usual Button with icon and optional text.
Button button = new Button("Download", VaadinIcon.DOWNLOAD.create());
button.setHeight("25px");
button.setWidth("25px");
button.getStyle().setPadding("0");
button.getStyle().setColor("white");
Anchor downloadLink = new Anchor((DownloadEvent event) -> {
event.setFileName("export.csv");
event.getResponse().setHeader("Content-Type", "text/csv");
try (OutputStream outputStream = event.getOutputStream()) {
//Todo download
//outputStream.write(csvBytes);
} catch (IOException e) {
throw new RuntimeException("Fehler beim Schreiben der CSV-Datei", e);
}
}, "Download");
downloadLink.add(button);
layout.add(downloadLink);