Directory

← Back

Copy2Clipboard widget for Vaadin

Copy text to the clipboard with the easy to use Copy2ClipboardButton

Author

Contributors

Rating

Copy2Clipboard uses the Flash and javascript from ZeroClipboard and bundles it into an easy to use widget. The Copy2ClipboardButton behaves just like a normal button but copies its text to the users clipboard. The button will work on every position on the page, even in nested panels and popups.

Sample code

// Create a new instance
Copy2ClipboardButton button = new Copy2ClipboardButton("Copy");
// Set the text to copy
button.setClipboardText("copy this to the clipboard");
	
// The listener will trigger on successful copy action
button.addListener(new ClipboardListener() {
	    
    @Override
    public void copiedToClipboard(ClipboardEvent event) {
        mainWindow.showNotification("Copied to the clipboard");
    }
});
Copy2ClipboardButton copyButton = new Copy2ClipboardButton("copy", true); // set retainClipElement to true
final PopupButton popup = new PopupButton("show popup");
popup.addComponent(copyButton);

copyButton.addListener(new ClipboardListener() {

	@Override
	public void copiedToClipboard(ClipboardEvent event) {
	    popup.setPopupVisible(true);
	}
});

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

Java 1.5+ compatibility added.

Released
2012-07-03
Maturity
BETA
License
Apache License 2.0

Compatibility

Framework
Vaadin 6.8+
Browser
Firefox
Google Chrome
Internet Explorer
Online