ContextMenu component

I have just released my second component for Vaadin 6.2, ContextMenu.

ContextMenu is a popup dialog menu that is inteded to be used with LayoutClickListeners. The purpose of this component is to popup an operating system like ContextMenu, that would apper when you right click on your desktop.

ContextMenu support submenus so it’s hierarchical. API resembels Vaadin’s MenuBar component, so by adding new item to menu you get reference to menu item as a return value. This reference can be used to insert sub menus.

Online demonstration is currently available from my virtuallypreinstalled site at

Sources are also available and are placed to

Great component!

Suggestion: how about automatically opening a submenu after a short hover period over the parent item?

Henri’s idea sounds very good indeed. I implemented the requested feature in version 2.1 and it’s now available. I also added checks to make sure that the opened menu will fit to screen area. If it won’t, it will be opened leftwards from clicked location. This also works with submenus.

New is also updated to virtuallypreinstalled, so you can test it from there if you wish.

I’m using your component as …

                ContextMenu cm= new ContextMenu();
                ContextMenu.ContextMenuItem color= cm.addItem("Color");
    		ContextMenu.ContextMenuItem white=color.addItem("White");
                ContextMenu.ContextMenuItem red=color.addItem("Red");
                ContextMenu.ContextMenuItem blue=color.addItem("Blue");
    		cm.addListener(new ContextMenu.ClickListener() {
				public void contextItemClick(
						org.vaadin.peter.contextmenu.ContextMenu.ClickEvent event) {
					// TODO Auto-generated method stub


but when i 've clicked on item white, red or blue then the output not shows “White”,“Red” or “Blue”

What am i doing wrong??

Thank you!!

Hi I’m a beginner with Vaadin and I’m trying to use this component but I always get this error:

Widgetset does not contain implementation for org.vaadin.peter.contextmenu.ContextMenu. Check its @ClientWidget mapping, widgetsets GWT module descrioption file and re-compile your widgetset. Unrendered UIDL:

org.vaadin.peter.contextmenu.ContextMenu(NO CLIENT IMPLEMENTATION FOUND)

What should I do? Thanks.

It seems you haven’t recompiled your widgetset after you’ve added the ContextMenu add-on to your project.

I’m having the same problem. Any help for this?

Hi and sorry that it’s taken so long to answer. I’ve been quite busy.

I looked through the code and was almost certain that there’s nothing wrong with it until I realized that there’s an elementary bug in ContextMenu. Click is recognized only when opening a sub menu.

Sorry about it, I’ll fix it right away and release a new version.

I’ve now released a new 2.2 version which is available from the Directory. Hopefully this one works with out any problems, sorry for the inconvenience.

Thanks, got it working finally.

But I have an other problem. How to set a proper position in the layoutClick method for the menu to appear.
The current:, event.getClientY());

Works only if you don’t scroll the window, if you do, the position get’s messed up.

Hi! I can’t get the hide()-function work for this component. Contextmenu disappears only if I click something, but I can’t find any other ways to remove it. It doesn’t help if I try to for example remove it from the layout.

Hi Jouni!

May be it’s posible in Eclipse, but i can’t find solution in Netbeans. What do you mean “recompile your widgetset”? Clean & Build in Netbeans?

For Netbeans, check out the help:
Using Vaadin add-ons in Netbeans

Jouni, Thank you very much!

Hi Heli,

Could you find any workarounf for disapearing the context menu? I have called the hide() function of the context menu every time when got a trigger in the contextItemClick(ClickEvent event) & it seems to work…


contextMenu.addListener(new ContextMenu.ClickListener() {
public void contextItemClick(ClickEvent event) {
// do actions

It would be great to have such features in the Table/Tree Action handler (I mean hierarchical, disabled or invisble entries).

This has been requested by others as well - see
the feature request in UserVoice

There is a related Vaadin enhancement request:
ticket #4343

Hi Peter,
What you’ve done is very useful.

I’ve got one issue with it. I have combined it with Drag&Drop Layout addon.
Each time I rightclick and don’t choose any of context menu (leftclick elsewhere)
and then drag and drop some layout element, the contextmenu appears without right-click,
like it is just hidden and not closed.

Thanx for any idea

Confirm! There is a bug :frowning:


I have the same problem with the widget-set.

I try to use the context menu in a
and I have re-compiled the widget-set very often.

What can I do?