I am using Vaadin and I want to add a caption to a button that has multiple lines - it should simply display String - 2 linebreaks - String
which I did not expect to be too hard to do.
Now sadly this turns out to be a little bit harder than I expected - My DataStructure should display a timetable (so I am using a structure that extends a grid) and I want all Slots to be filled with the according lectures and lectureres. However I am bound to use the Button-Element (not the NativeButton - the existing data structure needs a Button to work, I’d like to avoid writing it completely new), so using a HTML-Caption does not work.
So what I tried was a css-class like this:
.multiline-button {
width: 125px;
white-space: normal !important;
height: auto;
word-break: break-word !important;
word-wrap: break-word !important;
background-color: red !important;
}
(actually the background-color was just for testing if the style was applied) - I also tried setting these attributes manually in code via button.setStyle(name, value);
. Sadly none of those turns out to even be applied to the button. My Button Creation Code:
@CssImport("./styles/multiline-button.css")
public class NewScheduleTimetable<T> extends TimetableWithValue<T> {
@Override
protected Button createSlot(int day, int timeSlot) {
final Button slotButton = new Button();
/* even desperately tried removing all other themes, didn't even change anything
slotButton.getThemeNames().forEach(theme -> {
slotButton.removeThemeName(theme);
}); */
slotButton.setWidthFull();
slotButton.setHeight("125px");
slotButton.addClassName("multiline-button");
//this sets the text
if (hasValue(day, timeSlot)) {
slotButton.setText(getText(getValue(day, timeSlot)));
}
this.recalculateColumnWidths();
return slotButton;
}
}
Now the Buttons get created successfully and also display the name they should have - they are just missing the linebreaks for the captions. If I inspect the element in my browser, the captions do contain linebreaks (linebreaks are done via \n
).
So I am quite new to Vaadin, but usually these things are a five-minuter and not take me days to figure out different approaches (which all did not work out sadly) - what am I missing here?