Popup menu for window

Hello,

Please see the Vaadin demo
http://demo.vaadin.com/sampler#LabelPlain
: After click
View Source
, a popup window for source code is displayed.

My question is whether a popup menu can be added for the window, e.g. displaying
Download
, etc.

Thanks,
Watt

Sure !



public class subwindow extends Window{

 private MenuBar menubar = new MenuBar();
  subwindow(){
}

final MenuBar.MenuItem file = menubar.addItem("File", null);
  addComponent(menubar);

}

Treat the window that pops out , the same way you tree the “webpage” window.

Thank you for your reply, Lawal.

After I added your code in my project, a Vaadin window with a menubar can be popped up. It’s different from the usual style of Windows, so I have to expect another solution.

BTW, do you have any idea to capture mouse click in a Vaadin window? I couldn’t find a listener for it.

You could attach a click listener to the windows root layout

Window win = new Window("My Window");
((VerticalLayout)win.getContent()).addListener(new LayoutEvents.LayoutClickListener() {
    public void layoutClick(LayoutClickEvent event) {
        // Do something..                
    }
});

So what you need is a native browser window, right? They are opening in a bit different fashion than sub-windows (“Vaadin styled windows”).

See the windowing chapter from the Book of Vaadin for a complete explanation about the differences and code examples.

Hi John,

Thanks, LayoutEvents.LayoutClickListener() works. Unfortunately the mouse-click couldn’t always be captured.

Please have a test with following code:


public class Subwindow extends Window {
    public Subwindow() {
        setCaption("Sub Window");
        setModal(true); 
        getContent().setSizeUndefined();
        setWidth("100%");
        setHeight("100%");
        setPositionX(0);
        setPositionY(0); 
        ... 
        ((VerticalLayout) getContent()).addListener(new LayoutEvents.LayoutClickListener() {
            @Override
            public void layoutClick(LayoutClickEvent event) {
                System.out.println("layoutClick");

            }
        });
    }
}

If there is a table in its parent window, mouse-click don’t work within the table area. Should the case be considered specially?

Jouni:
What I need is to popup a menu (not a window), just like a browser displays a menu after mouse is right-clicked.
If MenuBar couldn’t support it directly, may I know your suggestion?

So is it a context menu you’re after? Then there’s an add-on in the Directory just for that.

Thank you, Jouni! The add-on “contextmenu” is exactly what I need.