How to add clickevent listener to Embedded component

hi everyone,

I try to add clickevent listener to Embedded component. But there is no this kind method for embedded.


You are right. Embedded is a generic embedding component. It might contain Java Applet, Flash, Image, Video, Sound, … And thus clicklistener is quite impossible to implement.

If your purpose is to embed an image and act when someone clicks on it, button component with icon (set to be your image) might do the trick. If not, please describe your need a bit better so that we could help.

Below is an example of using the Button to allow catching click events on an image.

import com.itmill.toolkit.ui.*;
import com.itmill.toolkit.terminal.*;

public class EmbeddedButton extends CustomComponent implements Button.ClickListener {
	Button thebutton;

	public EmbeddedButton(Resource icon) {
		/* Create a Button without a caption. */
		thebutton = new Button ();
		/* Set the icon of the button from a resource. */
		/* Set the style to link; this leaves out the button frame so you
		 * just have the image in the link. */
		/* Listen for ClickEvents. */

	/** Handle button click events from the button. */
	public void buttonClick (Button.ClickEvent event) {
		thebutton.setCaption ("You successfully clicked on the icon");

You use the component (from an Application class) as follows:

EmbeddedButton button = new EmbeddedButton(new ClassResource("smiley.jpg", this));