Directory

← Back

CopyToClipboard

A "copy to clipboard" button

Author

Rating

A simple "copy to clipboard" button. You can specify which text to copy to the clipboard and the image icon for the button. The component use a flash object to copy content to the clipboard. Because of this, the image should reside on the same domain as the swf component. The source is included in the jar file.

Sample code

                Window mainWindow = new Window("CopyToClipboard");
		Label label = new Label("Copy to clipboard example");
		mainWindow.addComponent(label);
		setMainWindow(mainWindow);

		final CopyToClipboardButton cp = new CopyToClipboardButton();
		mainWindow.addComponent(cp);

		mainWindow.addComponent(new Label("First set a text, then press the \"plus\" button"));

		final TextField tf = new TextField("Insert a text to copy");
		mainWindow.addComponent(tf);

		Button test = new Button("Set text to copy");

		test.addListener(new Button.ClickListener()
		{

			@Override
			public void buttonClick(ClickEvent event)
			{
				cp.setClipboardText((String) tf.getValue());
			}
		});
		mainWindow.addComponent(test);
		final TextField tf2 = new TextField("Button image url (should be on the same domain)");
		mainWindow.addComponent(tf2);

		Button test2 = new Button("Set button image");

		test2.addListener(new Button.ClickListener()
		{

			@Override
			public void buttonClick(ClickEvent event)
			{
				cp.setImageUrl((String) tf2.getValue());
			}
		});
		mainWindow.addComponent(test2);

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

Initial release

Released
2010-06-28
Maturity
EXPERIMENTAL
License
GNU Lesser General Public License v3.0 only

Compatibility

Framework
Vaadin 6.2+
Browser
Browser Independent
Online