ToolbarButton - Insufficient width for caption

Viewed 34

I want to add a caption to a toolbar button (with an icon) because if the button is grayed out (disabled) the description is not displayed. Caption is also displayed if the button is not enabled...

My problem is that I can't figure out how to enlarge the ToolbarButton field to fit the caption. The caption consists of 3 words and currently only the first word is displayed due to lack of space - relevant code snippet:


     toolbarButton = new ToolbarButton();
     toolbarButton.setIcon(ImgRes.ICON_PREVIEW);
     toolbarButton.setDescription("Preview Button Description");
     toolbarButton.setCaption("Preview Button Caption");
     toolbarButton.setWidth("100%");
     toolbarButton.setEnabled(false);       
     toolbarButton.addClickListener(e -> onPreviewButtonClicked());

     return toolbarButton;
 }

Can anyone help me how to solve my problem?

1 Answers

Try to set the min-width of the button so that it will always fit the content inside it:

toolbarButton.setMinWidth("max-content");
Related