First of all thank you for your work. Works fine if we pass to component already known content. But what in case if I want to add content dynamically, let say for every click to supply different content? Seems that this is not possible.
You can call setContent
to change the content dynamically. You just need to figure out a suitable event when to call it.
public class Foo extends VerticalLayout {
...
public void addClipboardHelper(Supplier<String> contentSupplier) {
Button button = new Button();
ClipboardHelper clipboardHelper = new ClipboardHelper("", button);
button.addClickListener(click -> clipboardHelper.setContent(contentSupplier.get()));
add(clipboardHelper);
}
}
Here copy never succeed on first click, always on second . Please can you help me what I can do regarding this example to make it work.
You’re setting the content on the click listener, which means it’s not available before the first click listener has executed on the server. If you add a call to clipboardHelper.setContent("something")
before the button.addClickListener()
you can set the clipboard content for the first call there.