{"id":39122,"date":"2016-07-12T15:00:09","date_gmt":"2016-07-12T12:00:09","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=39122"},"modified":"2019-04-09T12:59:41","modified_gmt":"2019-04-09T09:59:41","slug":"vaadin-menu-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/","title":{"rendered":"Vaadin Menu Example"},"content":{"rendered":"<p>We can organize commands into a menu.&nbsp;The menu allows us to stack multiple buttons in a logic way for the work flow.&nbsp;If we have too much commands or buttons in our user interface we need to consider to use a menu in our application.<\/p>\n<p>A menu has a tree structure with a main root with the top nodes attached to it and every node and sub-nodes could have child nodes, creating a tree structure.<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;\n<\/p>\n<h2>1. The tools<\/h2>\n<ul>\n<li>Java JDK 8<\/li>\n<li>Latest Eclipse Mars<\/li>\n<li>Vaadin 7.6.7<\/li>\n<li>Tomcat Server 8<\/li>\n<\/ul>\n<h2>2. Introduction<\/h2>\n<p>In this example we are going to create two menus.&nbsp;On each menu we are going to handle the click event and identify the parent and children item of the item we are clicking. Also we have some labels to give feedback of the action performed on the menu.<\/p>\n<h2>3. Prerequisites<\/h2>\n<ul>\n<li>JDK installed<\/li>\n<li>Eclipse Mars installed and working<\/li>\n<li>Vaadin plug-in installed<\/li>\n<li>Tomcat 8 installed and running<\/li>\n<\/ul>\n<h2>4. Set up the project<\/h2>\n<p>In the file menu choose File -&gt; New -&gt; Other<\/p>\n<p><figure id=\"attachment_34378\" aria-describedby=\"caption-attachment-34378\" style=\"width: 646px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/02\/01-New-Project-1.png\" rel=\"attachment wp-att-34378\"><img decoding=\"async\" class=\"size-full wp-image-34378\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/02\/01-New-Project-1.png\" alt=\"01 New Project\" width=\"646\" height=\"422\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/02\/01-New-Project-1.png 646w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/02\/01-New-Project-1-300x196.png 300w\" sizes=\"(max-width: 646px) 100vw, 646px\" \/><\/a><figcaption id=\"caption-attachment-34378\" class=\"wp-caption-text\">1 New Project<\/figcaption><\/figure><\/p>\n<p>Now from the list choose Vaadin 7 project<\/p>\n<p><figure id=\"attachment_34379\" aria-describedby=\"caption-attachment-34379\" style=\"width: 524px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/02\/02-Vaadin-Project-1.png\" rel=\"attachment wp-att-34379\"><img decoding=\"async\" class=\"size-full wp-image-34379\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/02\/02-Vaadin-Project-1.png\" alt=\"02 Vaadin Project\" width=\"524\" height=\"499\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/02\/02-Vaadin-Project-1.png 524w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/02\/02-Vaadin-Project-1-300x286.png 300w\" sizes=\"(max-width: 524px) 100vw, 524px\" \/><\/a><figcaption id=\"caption-attachment-34379\" class=\"wp-caption-text\">2 Vaadin Project<\/figcaption><\/figure><\/p>\n<p>Press&nbsp;next and name your project then press finish.<\/p>\n<h2>5. Coding the example<\/h2>\n<h3>5.1 Layouts and labels<\/h3>\n<p><span style=\"text-decoration: underline;\"><em>Layouts<\/em><\/span><\/p>\n<pre class=\"brush:java\">\t\tfinal VerticalLayout layout = new VerticalLayout();\n\t\tlayout.setMargin(true);\n\t\tlayout.setSpacing(true);\n\t\tsetContent(layout);\n\n\t\tHorizontalLayout menuLayout = new HorizontalLayout();\n\t\tmenuLayout.setSpacing(true);\n<\/pre>\n<p><code>&gt;final VerticalLayout layout = new VerticalLayout();<\/code>&nbsp;creates a vertical layout.<br \/>\n<code>&gt;layout.setMargin(true);<\/code> Sets the margin of the vertical layout.<\/p>\n<p><code>&gt;layout.setSpacing(true);<\/code> Gets some space between the items inside the layout.<br \/>\n<code>&gt;setContent(layout);<\/code> Sets the vertical layout as our main layout.<\/p>\n<p><code>&gt;HorizontalLayout menuLayout = new HorizontalLayout();<\/code> Creates an Horizontal layout.<br \/>\n<code>&gt;menuLayout.setSpacing(true);<\/code>&nbsp;Sets some space inside the items of the horizontal layout.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Labels<\/em><\/span><\/p>\n<pre class=\"brush:java\">\t\tLabel myFirstLabel = new Label(\"-\");\n\t\tmyFirstLabel.addStyleName(\"myfirstlabel\");\n\t\t\n\t\tLabel mySecondLabel = new Label(\"-\");\n\t\tmySecondLabel.addStyleName(\"mysecondlabel\");\n\t\t\n\t\tLabel secondMenuLabel = new Label(\"-\");\n\t\tsecondMenuLabel.addStyleName(\"secondmenulabel\");\n<\/pre>\n<p><code>&gt;Label myFirstLabel = new Label(\"-\");<\/code>&nbsp;Creates a label to show feedback when the user click a parent menu item.<br \/>\n<code>&gt;myFirstLabel.addStyleName(\"myfirstlabel\");<\/code> Assigns a style to the label.<\/p>\n<p><code>&gt;Label mySecondLabel = new Label(\"-\");<\/code> Creates another label to show when user click on a child menu item.<br \/>\n<code>&gt;mySecondLabel.addStyleName(\"mysecond<\/code> Adds a style to the second label.<\/p>\n<p><code>&gt;Label secondMenuLabel = new Label(\"<\/code> Creates a label to show the activity on the second menu.<br \/>\n<code>&gt;secondMenuLabel.addStyleName(\"secondmenulabel\");<\/code> Adds a style to the second menu label.<\/p>\n<h3>5.2 Styles<\/h3>\n<p><span style=\"text-decoration: underline;\"><em>First label style<\/em><\/span><\/p>\n<pre class=\"brush:java\">.v-label-myfirstlabel {\n    color: white;\n    text-align: center;\n    background-color: #6666FF;\t\n    border-color: white;\n    font-weight: bold;\n}\n<\/pre>\n<p>In this style we change the background color to a shade of blue and the text color to white, we center the text and the weight of the font is set to bold.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Second label style<\/em><\/span><\/p>\n<pre class=\"brush:java\">.v-label-mysecondlabel {\n    color: black;\n    text-align: center;\n    background-color: #EEFF44;\t\n    border-color: white;\n    font-weight: bold;\n}\n<\/pre>\n<p>In this style we change the background color to yellow and the text color to black.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Second menu label style<\/em><\/span><\/p>\n<pre class=\"brush:java\">.v-label-secondmenulabel {\n    color: white;\n    text-align: center;\n    background-color: #33AA33;\t\n    border-color: white;\n    font-weight: bold;\n}\n<\/pre>\n<p>In this style we change the background color to green and the text color to white.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>First menu style<\/em><\/span><\/p>\n<pre class=\"brush:java\">.v-menubar-firstmenu {\n\t    background: #AAAAEE;\n\t}  \n<\/pre>\n<p>We set the color of the menu to blue.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Second menu style<\/em><\/span><\/p>\n<pre class=\"brush:java\">.v-menubar-firstmenu {\n\t    background: #EEEEAA;\n\t}  \n<\/pre>\n<p>We set the color of the menu to yellow<\/p>\n<h3>5.3 Menu command callbacks<\/h3>\n<p><span style=\"text-decoration: underline;\"><em>Parent callback<\/em><\/span><\/p>\n<pre class=\"brush:java\">\t\tMenuBar.Command myFirstCommand = new MenuBar.Command() {\n\t\t\t\n\t\t\t@Override\n\t\t\tpublic void menuSelected(MenuItem selectedItem) {\n\t\t\t\tmyFirstLabel.setValue(selectedItem.getText());\n\t\t\t\tif(selectedItem.hasChildren()){\n\t\t\t\t\tList items = selectedItem.getChildren();\n\t\t\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\t\t\tfor(MenuItem item : items){\n\t\t\t\t\t\tsb.append(item.getText());\n\t\t\t\t\t}\n\t\t\t\t\tmySecondLabel.setValue(sb.toString());\n\t\t\t\t}else{\n\t\t\t\t\tmySecondLabel.setValue(\"-\");\n\t\t\t\t}\n\t\t\t\tsecondMenuLabel.setValue(\"-\");\n\t\t\t}\n\t\t};\n\n<\/pre>\n<p>We create a callback to the parent nodes of the menu.<\/p>\n<p><code>&gt;myFirstLabel.setValue(selectedItem.getText());<\/code>&nbsp;Gets the text of the selected menu item and set it to the first label.<br \/>\n<code>&gt;if(selectedItem.hasChildren()){<\/code> Checks if the selected menu item has children.<\/p>\n<p><code>&gt;List items = selectedItem.getChildren();<\/code> Gets all children of the selected node.<br \/>\n<code>&gt;StringBuilder sb = new StringBuilder();<\/code> Creates a string builder.<\/p>\n<p><code>&gt;for(MenuItem item : items){<\/code> For each one of the children items.<br \/>\n<code>&gt;sb.append(item.getText());<\/code> Appens the node to the string builder.<\/p>\n<p><code>&gt;mySecondLabel.setValue(sb.toString());<\/code> Converts the string builder into string and copy it to the second label.<br \/>\n<code>&gt;mySecondLabel.setValue(\"-\");<\/code> If the node has no children it clears the second label.<br \/>\n<code>&gt;secondMenuLabel.setValue(\"-\");<\/code> Clears the second menu label.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><span style=\"text-decoration: underline;\"><em>Children callback<\/em><\/span><\/p>\n<pre class=\"brush:java\">\t\tMenuBar.Command mySecondCommand = new MenuBar.Command() {\n\t\t\t\n\t\t\t@Override\n\t\t\tpublic void menuSelected(MenuItem selectedItem) {\n\t\t\t\tmySecondLabel.setValue(selectedItem.getText());\n\t\t\t\tMenuItem parent = selectedItem.getParent();\n\t\t\t\tif(parent!=null){\n\t\t\t\t\tmyFirstLabel.setValue(parent.getText());\n\t\t\t\t}\n\t\t\t\tsecondMenuLabel.setValue(\"-\");\n\t\t\t}\n\t\t};\n<\/pre>\n<p>We define a callback to capture bottom end nodes clicks.<\/p>\n<p><code>&gt;mySecondLabel.setValue(selectedItem.getText());<\/code> Sets the selected item text into the label value.<br \/>\n<code>&gt;MenuItem parent = selectedItem.getParent();<\/code> Gets the parent of the current node.<\/p>\n<p><code>&gt;if(parent!=null){<\/code> Checks if the selected item has parent.<br \/>\n<code>&gt;myFirstLabel.setValue(parent.getText());<\/code> Sets the first label to te parent value.<\/p>\n<p><code>&gt;secondMenuLabel.setValue(\"-\");<\/code> Clears the second menu label.<\/p>\n<p>We create a callback to use when the user interact with the second menu.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Second menu callback<\/em><\/span><\/p>\n<pre class=\"brush:java\">\t\tMenuBar.Command secondMenuCommand = new MenuBar.Command() {\n\t\t\t\n\t\t\t@Override\n\t\t\tpublic void menuSelected(MenuItem selectedItem) {\n\t\t\t\tmyFirstLabel.setValue(\"-\");\n\t\t\t\tmySecondLabel.setValue(\"-\");\n\t\t\t\tsecondMenuLabel.setValue(\"second menu clicked \" + selectedItem.getText());\n\t\t\t}\n\t\t};\n<\/pre>\n<p>We create a callback to use when the user interacts with the second menu.<\/p>\n<p><code>&gt;myFirstLabel.setValue(\"-\");<\/code>&nbsp;Clears the first label.<br \/>\n<code>&gt;mySecondLabel.setValue(\"-\");<\/code> Clears the second label.<\/p>\n<p><code>&gt;secondMenuLabel.setValue(\"second menu clicked \" + selectedItem.getText());<\/code> Sets the value of the second menu label.<\/p>\n<h3>5.4 First menu bar<\/h3>\n<p>We are going to create the top nodes first. Then we will add the child nodes level by level.&nbsp;For the icons we are going to use, the FontAwesome icons are included in Vaadin by default.<br \/>\nThe commands are attached on some of the nodes, only when we are going to use it.&nbsp;When we don&#8217;t need a command attached to a node, we use null as a parameter of the function.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Create the first menu<\/em><\/span><\/p>\n<pre class=\"brush:java\">\t\tMenuBar menu = new MenuBar();\n\t\tmenu.addStyleName(\"firstmenu\");\n\t\tMenuItem file = menu.addItem(\"File\", FontAwesome.FOLDER, null);\n\t\tMenuItem edit = menu.addItem(\"Edit\", null, null);\n\t\tMenuItem help = menu.addItem(\"Help\", FontAwesome.QUESTION_CIRCLE, null);\n<\/pre>\n<p><code>&gt;MenuBar menu = new MenuBar();<\/code>&nbsp;Creates the menu.<br \/>\n<code>&gt;menu.addStyleName(\"firstmenu\");<\/code> Adds the style of the menu.<\/p>\n<p><code>&gt;MenuItem file = menu.addItem(\"File\", FontAwesome.FOLDER, null);<\/code>&nbsp;Adds a &#8220;file&#8221; top node to the menu.<br \/>\n<code>&gt;MenuItem edit = menu.addItem(\"Edit\", null, null);<\/code> Adds a &#8220;Edit&#8221; top node.<\/p>\n<p><code>&gt;MenuItem help = menu.addItem(\"Help\", FontAwesome.QUESTION_CIRCLE, null);<\/code> Adds a &#8220;help&#8221; top node<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Populate the file node<\/em><\/span><\/p>\n<pre class=\"brush:java\">\t\tMenuItem create = file.addItem(\"New\", FontAwesome.NEWSPAPER_O, myFirstCommand);\n\t\tfile.addItem(\"Open\", FontAwesome.FOLDER_OPEN, myFirstCommand);\n\t\tfile.addItem(\"Close\", null, myFirstCommand);\n<\/pre>\n<p><code>&gt;MenuItem create = file.addItem(\"New\", FontAwesome.NEWSPAPER_O, myFirstCommand);<\/code>&nbsp;Adds the item &#8220;New&#8221; to the file node and saves it to a variable in order later to add children to it.<br \/>\n<code>&gt;file.addItem(\"Open\", FontAwesome.FOLDER_OPEN, myFirstCommand);<\/code> Adds a &#8220;Open node&#8221;<br \/>\n<code>&gt;file.addItem(\"Close\", null, myFirstCommand);<\/code> Adds another item to the &#8220;File&#8221; node called &#8220;Close&#8221;.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Populate the create node<\/em><\/span><\/p>\n<pre class=\"brush:java\">\t\tcreate.addItem(\"New Text File\", FontAwesome.FILE, mySecondCommand);\n\t\tcreate.addItem(\"Other\", mySecondCommand);\n<\/pre>\n<p><code>&gt;create.addItem(\"New Text File\", FontAwesome.FILE, mySecondCommand);<\/code> Adds the item &#8220;New text File&#8221; to the create node.<br \/>\n<code>&gt;create.addItem(\"Other\", mySecondCommand);<\/code> Adds the &#8220;Other&#8221; node to the &#8220;create&#8221; node.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Populate the edit node<\/em><\/span><\/p>\n<pre class=\"brush:java\">\t\tedit.addItem(\"Cut\", FontAwesome.CUT, myFirstCommand);\n\t\tedit.addItem(\"Copy\", FontAwesome.COPY, myFirstCommand);\n\t\tedit.addItem(\"Paste\", FontAwesome.PASTE, myFirstCommand);\n<\/pre>\n<p><code>&gt;edit.addItem(\"Cut\", FontAwesome.CUT, myFirstCommand);<\/code> Adds the &#8220;Cut&#8221; node to the &#8220;edit&#8221; node.<br \/>\n<code>&gt;edit.addItem(\"Copy\", FontAwesome.COPY, myFirstCommand);<\/code> Adds the &#8220;Copy&#8221; node to the &#8220;edit&#8221; node.<br \/>\n<code>&gt;edit.addItem(\"Paste\", FontAwesome.PASTE, myFirstCommand);<\/code> Adds the &#8220;Paste&#8221; node to the &#8220;edit&#8221; node.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Populate the help menu<\/em><\/span><\/p>\n<pre class=\"brush:java\">\t\thelp.addItem(\"Search\", FontAwesome.SEARCH, myFirstCommand);\n\t\tMenuItem index = help.addItem(\"Index\", myFirstCommand);\n\t\tMenuItem level01 = index.addItem(\"level01\", mySecondCommand);\n\t\tMenuItem level02 = level01.addItem(\"level02\", mySecondCommand);\n\t\tlevel02.addItem(\"level03\", mySecondCommand);\n\t\thelp.addSeparator();\n\t\thelp.addItem(\"About\", myFirstCommand);\n<\/pre>\n<p><code>&gt;help.addItem(\"Search\", FontAwesome.SEARCH, myFirstCommand);<\/code> Adds the search item to the help menu.<br \/>\n<code>&gt;MenuItem index = help.addItem(\"Index\", myFirstCommand);<\/code> Adds the index item to the help menu.<\/p>\n<p><code>&gt;MenuItem level01 = index.addItem(\"level01\", mySecondCommand);<\/code> Adds the level01 item to the index menu.<br \/>\n<code>&gt;MenuItem level02 = level01.addItem(\"level02\", mySecondCommand);<\/code> Adds the level02 node to the level01 node.<\/p>\n<p><code>&gt;level02.addItem(\"level03\", mySecondCommand);<\/code> Adds the level03 node to the level02 node.<br \/>\n<code>&gt;help.addSeparator();<\/code> Adds a separator to the menu.<\/p>\n<p><code>&gt;help.addItem(\"About\", myFirstCommand);<\/code> Adds the about menu item to the help menu.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Create the second Menu Bar<\/em><\/span><\/p>\n<pre class=\"brush:java\">\t\tMenuBar menu2 = new MenuBar();\n\t\tmenu2.addStyleName(\"secondmenu\");\n\t\tMenuItem item1 = menu2.addItem(\"Item1\", FontAwesome.ADN, null);\n\t\titem1.addItem(\"X1\", FontAwesome.AMBULANCE, secondMenuCommand);\n\t\titem1.addItem(\"X2\", FontAwesome.WIFI, secondMenuCommand);\n\t\titem1.addItem(\"X3\", FontAwesome.ADJUST, secondMenuCommand);\n\t\tmenu2.addItem(\"Item2\", FontAwesome._500PX, secondMenuCommand);\n\t\tmenu2.addItem(\"Menu3\", FontAwesome.QUESTION_CIRCLE, secondMenuCommand);\n<\/pre>\n<p><code>&gt;MenuBar menu2 = new MenuBar(); C<\/code>reates the menu bar.<br \/>\n<code>&gt;menu2.addStyleName(\"secondmenu\");<\/code> Adds he style to the menu.[ulp id=&#8217;YBvYYzEYBUrADqmI&#8217;]<\/p>\n<p><code>&gt;MenuItem item1 = menu2.addItem(\"Item1\", FontAwesome.ADN, null);<\/code> Adds the item &#8220;Item1&#8221; to the menu root.<br \/>\n<code>&gt;item1.addItem(\"X1\", FontAwesome.AMBULANCE, secondMenuCommand);<\/code> Adds the node &#8220;X1&#8221; to the &#8220;item1&#8221; menu.<\/p>\n<p><code>&gt;item1.addItem(\"X2\", FontAwesome.WIFI, secondMenuCommand);<\/code> Adds the node &#8220;X2&#8221; to the &#8220;item1&#8221; menu.<br \/>\n<code>&gt;item1.addItem(\"X3\", FontAwesome.ADJUST, secondMenuCommand);<\/code> Adds the node &#8220;X3&#8221; to the &#8220;item1&#8221; menu.<\/p>\n<p><code>&gt;menu2.addItem(\"Item2\", FontAwesome._500PX, secondMenuCommand);<\/code> Adds the item &#8220;Item2&#8221; to the menu root.<br \/>\n<code>&gt;menu2.addItem(\"Menu3\", FontAwesome.QUESTION_CIRCLE, secondMen<\/code> Adds the item &#8220;Menu3&#8221; to the menu root.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>Add the widgets to the layout<\/em><\/span><\/p>\n<pre class=\"brush:java\">\t\tmenuLayout.addComponent(menu);\n\t\tmenuLayout.addComponent(menu2);\n\t\tlayout.addComponent(menuLayout);\n\t\tlayout.addComponent(myFirstLabel);\n\t\tlayout.addComponent(mySecondLabel);\n\t\tlayout.addComponent(secondMenuLabel);\n<\/pre>\n<p><code>&gt;menuLayout.addComponent(menu);<\/code> Adds the first menu to the horizontal layout.<br \/>\n<code>&gt;menuLayout.addComponent(menu2);<\/code> Adds the second menu to the horizontal layout.<\/p>\n<p><code>&gt;layout.addComponent(menuLayout);<\/code> Adds the horizontal layout to the main vertical layout.<br \/>\n<code>&gt;layout.addComponent(myFirstLabel);<\/code> Adds the first label to the main vertical layout.<\/p>\n<p><code>&gt;layout.addComponent(mySecondLabel);<\/code> Adds the second label to the main vertical layout.<br \/>\n<code>&gt;layout.addComponent(secondMenuLabel);<\/code> Adds the second menu label to the main vertical layout.<\/p>\n<h2>6. The complete source code<\/h2>\n<p><span style=\"text-decoration: underline;\"><em>vaadinmenu.scss<\/em><\/span><\/p>\n<pre class=\"brush:java\">@import \"..\/valo\/valo.scss\";\n\n@mixin vaadinmenu {\n  @include valo;\n\n.v-label-myfirstlabel {\n    color: white;\n    text-align: center;\n    background-color: #6666FF;\t\n    border-color: white;\n    font-weight: bold;\n}\n\n.v-label-mysecondlabel {\n    color: black;\n    text-align: center;\n    background-color: #EEFF44;\t\n    border-color: white;\n    font-weight: bold;\n}\n\n.v-label-secondmenulabel {\n    color: white;\n    text-align: center;\n    background-color: #33AA33;\t\n    border-color: white;\n    font-weight: bold;\n}\n\n.v-menubar-firstmenu {\n\t    background: #AAAAEE;\n\t}  \n\n.v-menubar-secondmenu {\n\t    background: #EEEEAA;\n\t}  \n\n\n}\n<\/pre>\n<p><span style=\"text-decoration: underline;\"><em>VaadinmenuUI.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.example.vaadinmenu;\n\nimport java.util.List;\n\nimport javax.servlet.annotation.WebServlet;\n\nimport com.vaadin.annotations.Theme;\nimport com.vaadin.annotations.VaadinServletConfiguration;\nimport com.vaadin.server.FontAwesome;\nimport com.vaadin.server.VaadinRequest;\nimport com.vaadin.server.VaadinServlet;\nimport com.vaadin.ui.HorizontalLayout;\nimport com.vaadin.ui.Label;\nimport com.vaadin.ui.MenuBar;\nimport com.vaadin.ui.MenuBar.MenuItem;\nimport com.vaadin.ui.UI;\nimport com.vaadin.ui.VerticalLayout;\n\n@SuppressWarnings(\"serial\")\n@Theme(\"vaadinmenu\")\npublic class VaadinmenuUI extends UI {\n\n\t@WebServlet(value = \"\/*\", asyncSupported = true)\n\t@VaadinServletConfiguration(productionMode = false, ui = VaadinmenuUI.class, widgetset = \"com.example.vaadinmenu.widgetset.VaadinmenuWidgetset\")\n\tpublic static class Servlet extends VaadinServlet {\n\t}\n\n\t@Override\n\tprotected void init(VaadinRequest request) {\n\t\tfinal VerticalLayout layout = new VerticalLayout();\n\t\tlayout.setMargin(true);\n\t\tlayout.setSpacing(true);\n\t\tsetContent(layout);\n\n\t\tHorizontalLayout menuLayout = new HorizontalLayout();\n\t\tmenuLayout.setSpacing(true);\n\t\t\n\t\tLabel myFirstLabel = new Label(\"-\");\n\t\tmyFirstLabel.addStyleName(\"myfirstlabel\");\n\t\t\n\t\tLabel mySecondLabel = new Label(\"-\");\n\t\tmySecondLabel.addStyleName(\"mysecondlabel\");\n\t\t\n\t\tLabel secondMenuLabel = new Label(\"-\");\n\t\tsecondMenuLabel.addStyleName(\"secondmenulabel\");\n\t\t\n\t\tMenuBar.Command myFirstCommand = new MenuBar.Command() {\n\t\t\t\n\t\t\t@Override\n\t\t\tpublic void menuSelected(MenuItem selectedItem) {\n\t\t\t\tmyFirstLabel.setValue(selectedItem.getText());\n\t\t\t\tif(selectedItem.hasChildren()){\n\t\t\t\t\tList items = selectedItem.getChildren();\n\t\t\t\t\tStringBuilder sb = new StringBuilder();\n\t\t\t\t\tfor(MenuItem item : items){\n\t\t\t\t\t\tsb.append(item.getText());\n\t\t\t\t\t}\n\t\t\t\t\tmySecondLabel.setValue(sb.toString());\n\t\t\t\t}else{\n\t\t\t\t\tmySecondLabel.setValue(\"-\");\n\t\t\t\t}\n\t\t\t\tsecondMenuLabel.setValue(\"-\");\n\t\t\t}\n\t\t};\n\t\t\n\t\tMenuBar.Command mySecondCommand = new MenuBar.Command() {\n\t\t\t\n\t\t\t@Override\n\t\t\tpublic void menuSelected(MenuItem selectedItem) {\n\t\t\t\tmySecondLabel.setValue(selectedItem.getText());\n\t\t\t\tMenuItem parent = selectedItem.getParent();\n\t\t\t\tif(parent!=null){\n\t\t\t\t\tmyFirstLabel.setValue(parent.getText());\n\t\t\t\t}\n\t\t\t\tsecondMenuLabel.setValue(\"-\");\n\t\t\t}\n\t\t};\n\n\t\tMenuBar.Command secondMenuCommand = new MenuBar.Command() {\n\t\t\t\n\t\t\t@Override\n\t\t\tpublic void menuSelected(MenuItem selectedItem) {\n\t\t\t\tmyFirstLabel.setValue(\"-\");\n\t\t\t\tmySecondLabel.setValue(\"-\");\n\t\t\t\tsecondMenuLabel.setValue(\"second menu clicked \" + selectedItem.getText());\n\t\t\t}\n\t\t};\n\n\t\tMenuBar menu = new MenuBar();\n\t\tmenu.addStyleName(\"firstmenu\");\n\t\tMenuItem file = menu.addItem(\"File\", FontAwesome.FOLDER, null);\n\t\tMenuItem edit = menu.addItem(\"Edit\", null, null);\n\t\tMenuItem help = menu.addItem(\"Help\", FontAwesome.QUESTION_CIRCLE, null);\n\t\t\n\t\tMenuItem create = file.addItem(\"New\", FontAwesome.NEWSPAPER_O, myFirstCommand);\n\t\tfile.addItem(\"Open\", FontAwesome.FOLDER_OPEN, myFirstCommand);\n\t\tfile.addItem(\"Close\", null, myFirstCommand);\n\t\t\n\t\tcreate.addItem(\"New Text File\", FontAwesome.FILE, mySecondCommand);\n\t\tcreate.addItem(\"Other\", mySecondCommand);\n\t\t\n\t\tedit.addItem(\"Cut\", FontAwesome.CUT, myFirstCommand);\n\t\tedit.addItem(\"Copy\", FontAwesome.COPY, myFirstCommand);\n\t\tedit.addItem(\"Paste\", FontAwesome.PASTE, myFirstCommand);\n\t\t\n\t\thelp.addItem(\"Search\", FontAwesome.SEARCH, myFirstCommand);\n\t\tMenuItem index = help.addItem(\"Index\", myFirstCommand);\n\t\tMenuItem level01 = index.addItem(\"level01\", mySecondCommand);\n\t\tMenuItem level02 = level01.addItem(\"level02\", mySecondCommand);\n\t\tlevel02.addItem(\"level03\", mySecondCommand);\n\t\thelp.addSeparator();\n\t\thelp.addItem(\"About\", myFirstCommand);\n\n\t\tMenuBar menu2 = new MenuBar();\n\t\tmenu2.addStyleName(\"secondmenu\");\n\t\tMenuItem item1 = menu2.addItem(\"Item1\", FontAwesome.ADN, null);\n\t\titem1.addItem(\"X1\", FontAwesome.AMBULANCE, secondMenuCommand);\n\t\titem1.addItem(\"X2\", FontAwesome.WIFI, secondMenuCommand);\n\t\titem1.addItem(\"X3\", FontAwesome.ADJUST, secondMenuCommand);\n\t\tmenu2.addItem(\"Item2\", FontAwesome._500PX, secondMenuCommand);\n\t\tmenu2.addItem(\"Menu3\", FontAwesome.QUESTION_CIRCLE, secondMenuCommand);\n\t\t\n\t\tmenuLayout.addComponent(menu);\n\t\tmenuLayout.addComponent(menu2);\n\t\tlayout.addComponent(menuLayout);\n\t\tlayout.addComponent(myFirstLabel);\n\t\tlayout.addComponent(mySecondLabel);\n\t\tlayout.addComponent(secondMenuLabel);\n\t}\n\n}\n<\/pre>\n<h2>7. Running the example<\/h2>\n<p>Right click on the project folder and choose Run as -&gt; Run on server choose Tomcat 8 server and press finish.<\/p>\n<h2>8. Results<\/h2>\n<p>Our main menu.<\/p>\n<p><figure id=\"attachment_39124\" aria-describedby=\"caption-attachment-39124\" style=\"width: 636px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/3-Main-Menu.png\"><img decoding=\"async\" class=\"size-full wp-image-39124\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/3-Main-Menu.png\" alt=\"3 Main Menu\" width=\"636\" height=\"295\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/3-Main-Menu.png 636w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/3-Main-Menu-300x139.png 300w\" sizes=\"(max-width: 636px) 100vw, 636px\" \/><\/a><figcaption id=\"caption-attachment-39124\" class=\"wp-caption-text\">3 Main Menu<\/figcaption><\/figure><\/p>\n<p>The file menu.<\/p>\n<p><figure id=\"attachment_39125\" aria-describedby=\"caption-attachment-39125\" style=\"width: 643px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/4-File-Menu.png\"><img decoding=\"async\" class=\"size-full wp-image-39125\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/4-File-Menu.png\" alt=\"4 File Menu\" width=\"643\" height=\"296\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/4-File-Menu.png 643w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/4-File-Menu-300x138.png 300w\" sizes=\"(max-width: 643px) 100vw, 643px\" \/><\/a><figcaption id=\"caption-attachment-39125\" class=\"wp-caption-text\">4 File Menu<\/figcaption><\/figure><\/p>\n<p>The help menu.<\/p>\n<p><figure id=\"attachment_39126\" aria-describedby=\"caption-attachment-39126\" style=\"width: 643px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/5-Help-Menu.png\"><img decoding=\"async\" class=\"size-full wp-image-39126\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/5-Help-Menu.png\" alt=\"5 Help Menu\" width=\"643\" height=\"295\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/5-Help-Menu.png 643w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/5-Help-Menu-300x138.png 300w\" sizes=\"(max-width: 643px) 100vw, 643px\" \/><\/a><figcaption id=\"caption-attachment-39126\" class=\"wp-caption-text\">5 Help Menu<\/figcaption><\/figure><\/p>\n<p>Our second menu.<\/p>\n<p><figure id=\"attachment_39127\" aria-describedby=\"caption-attachment-39127\" style=\"width: 643px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/6-Second-menu.png\"><img decoding=\"async\" class=\"size-full wp-image-39127\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/6-Second-menu.png\" alt=\"6 Second menu\" width=\"643\" height=\"295\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/6-Second-menu.png 643w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/6-Second-menu-300x138.png 300w\" sizes=\"(max-width: 643px) 100vw, 643px\" \/><\/a><figcaption id=\"caption-attachment-39127\" class=\"wp-caption-text\">6 Second menu<\/figcaption><\/figure><\/p>\n<h2>9. Download the Source Code<\/h2>\n<p>This was an example of: Vaadin MenuBar.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the Eclipse project here:&nbsp;<strong><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/VaadinMenu.zip\">VaadinMenu<\/a><br \/>\n<\/strong><\/div>\n","protected":false},"excerpt":{"rendered":"<p>We can organize commands into a menu.&nbsp;The menu allows us to stack multiple buttons in a logic way for the work flow.&nbsp;If we have too much commands or buttons in our user interface we need to consider to use a menu in our application. A menu has a tree structure with a main root with &hellip;<\/p>\n","protected":false},"author":77,"featured_media":33079,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1358],"tags":[],"class_list":["post-39122","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vaadin"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Vaadin Menu Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"We can organize commands into a menu.&nbsp;The menu allows us to stack multiple buttons in a logic way for the work flow.&nbsp;If we have too much\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Vaadin Menu Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"We can organize commands into a menu.&nbsp;The menu allows us to stack multiple buttons in a logic way for the work flow.&nbsp;If we have too much\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2016-07-12T12:00:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-04-09T09:59:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/01\/vaadin-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Jesus Boadas\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@jboadas\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jesus Boadas\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/\"},\"author\":{\"name\":\"Jesus Boadas\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/506f9c2b38156c7f94bba77757206dd7\"},\"headline\":\"Vaadin Menu Example\",\"datePublished\":\"2016-07-12T12:00:09+00:00\",\"dateModified\":\"2019-04-09T09:59:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/\"},\"wordCount\":1101,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/01\/vaadin-logo.jpg\",\"articleSection\":[\"Vaadin\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/\",\"name\":\"Vaadin Menu Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/01\/vaadin-logo.jpg\",\"datePublished\":\"2016-07-12T12:00:09+00:00\",\"dateModified\":\"2019-04-09T09:59:41+00:00\",\"description\":\"We can organize commands into a menu.&nbsp;The menu allows us to stack multiple buttons in a logic way for the work flow.&nbsp;If we have too much\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/01\/vaadin-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/01\/vaadin-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Vaadin\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/vaadin\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Vaadin Menu Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/506f9c2b38156c7f94bba77757206dd7\",\"name\":\"Jesus Boadas\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/10\/Jesus-Boadas_avatar_1476120926-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/10\/Jesus-Boadas_avatar_1476120926-96x96.jpg\",\"caption\":\"Jesus Boadas\"},\"description\":\"I'm a self taught programmer, I began programming back in 1991 using an IBM A10 mainframe with Pascal an Assembler IBM 360\/70 emulator and Turbo C on a X86 PC, since that I work for the banking industry with emerging technologies like Fox Pro, Visual Fox Pro, Visual Basic, Visual C++, Borland C++, lately I moved out to the Airline industry, leading designing and programming in-house web applications with Flex, Actionscript, PHP, Python and Rails and in the last 7 years I focused all my work in Java, working on Linux servers using GlassFish, TomCat, Apache and MySql.\",\"sameAs\":[\"http:\/\/www.javacodegeeks.com\/\",\"https:\/\/ve.linkedin.com\/in\/jesus-boadas\",\"https:\/\/x.com\/jboadas\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/jesus-boadas\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Vaadin Menu Example - Java Code Geeks","description":"We can organize commands into a menu.&nbsp;The menu allows us to stack multiple buttons in a logic way for the work flow.&nbsp;If we have too much","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/","og_locale":"en_US","og_type":"article","og_title":"Vaadin Menu Example - Java Code Geeks","og_description":"We can organize commands into a menu.&nbsp;The menu allows us to stack multiple buttons in a logic way for the work flow.&nbsp;If we have too much","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2016-07-12T12:00:09+00:00","article_modified_time":"2019-04-09T09:59:41+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/01\/vaadin-logo.jpg","type":"image\/jpeg"}],"author":"Jesus Boadas","twitter_card":"summary_large_image","twitter_creator":"@jboadas","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Jesus Boadas","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/"},"author":{"name":"Jesus Boadas","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/506f9c2b38156c7f94bba77757206dd7"},"headline":"Vaadin Menu Example","datePublished":"2016-07-12T12:00:09+00:00","dateModified":"2019-04-09T09:59:41+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/"},"wordCount":1101,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/01\/vaadin-logo.jpg","articleSection":["Vaadin"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/","name":"Vaadin Menu Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/01\/vaadin-logo.jpg","datePublished":"2016-07-12T12:00:09+00:00","dateModified":"2019-04-09T09:59:41+00:00","description":"We can organize commands into a menu.&nbsp;The menu allows us to stack multiple buttons in a logic way for the work flow.&nbsp;If we have too much","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/01\/vaadin-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/01\/vaadin-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/vaadin\/vaadin-menu-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/"},{"@type":"ListItem","position":4,"name":"Vaadin","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/vaadin\/"},{"@type":"ListItem","position":5,"name":"Vaadin Menu Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/506f9c2b38156c7f94bba77757206dd7","name":"Jesus Boadas","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/10\/Jesus-Boadas_avatar_1476120926-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/10\/Jesus-Boadas_avatar_1476120926-96x96.jpg","caption":"Jesus Boadas"},"description":"I'm a self taught programmer, I began programming back in 1991 using an IBM A10 mainframe with Pascal an Assembler IBM 360\/70 emulator and Turbo C on a X86 PC, since that I work for the banking industry with emerging technologies like Fox Pro, Visual Fox Pro, Visual Basic, Visual C++, Borland C++, lately I moved out to the Airline industry, leading designing and programming in-house web applications with Flex, Actionscript, PHP, Python and Rails and in the last 7 years I focused all my work in Java, working on Linux servers using GlassFish, TomCat, Apache and MySql.","sameAs":["http:\/\/www.javacodegeeks.com\/","https:\/\/ve.linkedin.com\/in\/jesus-boadas","https:\/\/x.com\/jboadas"],"url":"https:\/\/examples.javacodegeeks.com\/author\/jesus-boadas\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/39122","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/77"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=39122"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/39122\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/33079"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=39122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=39122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=39122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}