Menu Buttons

Menu buttons are similar to list buttons, but provide access to "drop-down" menus rather than list views. They are often used in toolbars, but can be placed anywhere within an application's user interface.

The following sample application demonstrates the use of a menu button. Selecting an option from the menu button on the left adds the corresponding component type to the content area on the right:

The BXML source for the application is as follows:

            <menus:MenuButtons title="Menu Buttons" maximized="true"
                <Border styles="{padding:8}">
                    <TablePane styles="{horizontalSpacing:4}">
                            <TablePane.Column width="-1"/>
                            <TablePane.Column width="1*"/>

                        <TablePane.Row height="1*">
                            <BoxPane orientation="vertical">
                                <MenuButton buttonData="Add Component">
                                            <Menu.Item buttonData="Push Button" action="addPushButton"/>
                                            <Menu.Item buttonData="Checkbox" action="addCheckbox"/>
                                            <Menu.Item buttonData="Radio Button" action="addRadioButton"/>

                                    <BoxPane bxml:id="componentBoxPane" orientation="vertical"
                                        styles="{padding:4, spacing:4}"/>

Like the previous example, it defines a set of menu items that are associated with named actions. The Java source, which defines the actions, is shown below:

            package org.apache.pivot.tutorials.menus;


            import org.apache.pivot.beans.Bindable;
            import org.apache.pivot.collections.Map;
            import org.apache.pivot.util.Resources;
            import org.apache.pivot.wtk.Action;
            import org.apache.pivot.wtk.BoxPane;
            import org.apache.pivot.wtk.Checkbox;
            import org.apache.pivot.wtk.Component;
            import org.apache.pivot.wtk.PushButton;
            import org.apache.pivot.wtk.RadioButton;
            import org.apache.pivot.wtk.Window;

            public class MenuButtons extends Window implements Bindable {
                private BoxPane componentBoxPane = null;

                public MenuButtons() {
                    Action.getNamedActions().put("addPushButton", new Action() {
                        public void perform(Component source) {
                            componentBoxPane.add(new PushButton("Push button"));


                    Action.getNamedActions().put("addCheckbox", new Action() {
                        public void perform(Component source) {
                            componentBoxPane.add(new Checkbox("Checkbox"));

                    Action.getNamedActions().put("addRadioButton", new Action() {
                        public void perform(Component source) {
                            componentBoxPane.add(new RadioButton("Radio button"));

                public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
                    componentBoxPane = (BoxPane)namespace.get("componentBoxPane");

Next: Color Choosers