MenuBar change subMenu position



Problem solved

Hi,

I’m new in Vaadin and don’t know it is possible
is there any way to set the position or direction where the MenuBar open the submenu?
I want that my menubar open the submenu to the right and not downward.

Thank you

Hi,

seems to me that the positioning logic is currently non-configurable. You can find it at com.vaadin.client.ui.VMenuBar.showChildMenuAt(CustomMenuItem, int, int) if you want to try out extending / modifying the widget. Of course you should also create an enhancement ticket at dev.vaadin.com so this feature might be eventually added.

-tepi

Hi,

I want to try out extending / modifying the widget but how?
I tried to init an VMenuBar with

import com.vaadin.client.ui.VMenuBar;
[…]

VMenuBar vBar = new VMenuBar();
[…]

but I get an java.lang.NoClassDefFoundError: com/vaadin/client/ui/VMenuBar.
(full console log see at the file)

I don’t know what I do wrong or what I have to do.

I use Vaadin 7.1.5 in an maven (3.0) Project with Servlet version 3.0 and apache-tomcat-7.0.42

thanks
13201.txt (4.84 KB)

Hi,

you have to do the extending on the client side. If you’re not familiar with client-side development, you might want to read about it in
the book
. So basically you would need to create your own widget which extends VMenuBar.

-tepi

Hi,

I solved my Problem:


[...]

VerticalLayout layout = new VerticalLayout();
    	HorizontalLayout help = new HorizontalLayout();
    	
    	final PopupView popup = new PopupView(new OwnPop()); 
    	popup.setHideOnMouseOut(true);
    	Button buttonWithIcon = new Button();
    	buttonWithIcon.setIcon(new ThemeResource("any icon1"));
    	buttonWithIcon.setStyleName(BaseTheme.BUTTON_LINK);
    	buttonWithIcon.addClickListener(new ClickListener() {
			
			@Override
			public void buttonClick(com.vaadin.ui.Button.ClickEvent event) {
				popup.setPopupVisible(true);
				
			}
		});
    	
        help.addComponent(popup);
        help.addComponent(buttonWithIcon);
        layout.addComponent(help);        
[...]

and

class OwnPop implements PopupView.Content{
    	
		@Override
		public String getMinimizedValueAsHTML() {
			return "";
		}

		@Override
		public Component getPopupComponent() {
	    	Button button = new Button();
	    	button.setIcon(new ThemeResource("<any icon>"));
	    	button.setStyleName(BaseTheme.BUTTON_LINK);
			HorizontalLayout innerLayout = new HorizontalLayout();
			innerLayout.setSpacing(true);
			
			button.addClickListener(new ClickListener() {
				
				@Override
				public void buttonClick(ClickEvent event) {
					Notification.show("funktioniert");
					
				}
			});
			VerticalLayout right = new VerticalLayout();
			
			Command command = null;
			MenuBar menu = new MenuBar();
			MenuItem mainItem1 = menu.addItem("mainItem1", command);
			MenuItem mainItem2 = menu.addItem("mainItem1", command);
			MenuItem mainItem3 = menu.addItem("mainItem1", command);
			mainItem1.addItem("subitem", command);
			mainItem1.addItem("subitem", command);
			mainItem1.addItem("subitem", command);
			mainItem2.addItem("subitem", command);
			mainItem2.addItem("subitem", command);
			mainItem3.addItem("subitem", command);
		 	innerLayout.addComponent(button);
	    	right.addComponent(menu);
	    	innerLayout.addComponent(right);
	    	innerLayout.setComponentAlignment(right, Alignment.MIDDLE_CENTER);
			return innerLayout;
		}
    	
    }