Google Apps Script

Class MenuBar

A standard menu bar widget.

A menu bar can contain any number of menu items, each of which can either fire an event handler or open a cascaded menu bar.

Internally, UiApp widgets are built on top of the Google Web Toolkit, and it can sometimes be helpful to look at the GWT documentation directly. You can find the MenuBar documentation here.

Methods

MethodReturn typeBrief description
addCloseHandler(handler)MenuBarAdd a handler for close events.
addItem(item)MenuBarAdd a new menu item to this MenuBar.
addItem(text, asHtml, command)MenuBarCreates a new menu item with the given text and command and adds it to this MenuBar.
addItem(text, asHtml, subMenu)MenuBarCreates a new menu item with the given text and submenu and adds it to this MenuBar.
addItem(text, command)MenuBarCreates a new menu item with the given text and command and adds it to this MenuBar.
addItem(text, subMenu)MenuBarCreates a new menu item with the given text and submenu and adds it to this MenuBar.
addSeparator()MenuBarAdd a separator to the MenuBar.
addSeparator(separator)MenuBarAdd a separator to the MenuBar.
addStyleDependentName(styleName)MenuBarSets the dependent style name of this MenuBar.
addStyleName(styleName)MenuBarAdds a style name to this MenuBar.
getId()StringReturns the id that has been assigned to this object.
getTag()StringGets the text tag of this MenuBar.
getType()StringGets the type of this object.
setAnimationEnabled(animationEnabled)MenuBarSets whether opening and closing the MenuBar is animated.
setAutoOpen(autoOpen)MenuBarSets whether this menu bar's child menus will open when the mouse is moved over it.
setHeight(height)MenuBarSets the height of this MenuBar.
setId(id)MenuBarSets the id of this MenuBar.
setPixelSize(width, height)MenuBarSets the size of this MenuBar in pixels.
setSize(width, height)MenuBarSets the size of this MenuBar.
setStyleAttribute(attribute, value)MenuBarSets one of this MenuBar's style attributes to a new value.
setStyleAttributes(attributes)MenuBarSets this MenuBar's style attributes.
setStyleName(styleName)MenuBarSets the style name of this MenuBar.
setStylePrimaryName(styleName)MenuBarSets the primary style name of this MenuBar.
setTag(tag)MenuBarSets the text tag of this MenuBar.
setTitle(title)MenuBarSets the hover title of this MenuBar.
setVisible(visible)MenuBarSets whether this MenuBar is visible.
setWidth(width)MenuBarSets the width of this MenuBar.

Detailed documentation

addCloseHandler(handler)

Add a handler for close events.

Note that you can have multiple handlers for the same event on the same widget. They will be called in the order that they were added to the widget, although ServerHandlers may appear to happen simultaneously.

The handler passes back some information to the server about what happened. This information can be accessed as follows:

 
function doGet() {
   var app = UiApp.createApplication();
   var item1 = app.createTreeItem("item1");
   item1.addItem(app.createTreeItem("item2"));
   var tree = app.createTree();
   tree.addItem(item1);
   var handler = app.createServerHandler("handlerFunction");
   tree.addCloseHandler(handler)
   app.add(tree);
   return app;
 }

 function handlerFunction(eventInfo) {
   var parameter = eventInfo.parameter;
   // the type of event, in this case "close".
   var eventType = parameter.eventType;
   // the id of the widget that fired this event.
   var source = parameter.source;
 }
 
In addition, the values of certain widgets can be sent up with the event as well as "callback elements." See the documentation of ServerHandler for more information.

Parameters

NameTypeDescription
handlerHandlerthe handler to execute when the event occurs. This can be a ClientHandler or a ServerHandler.

Return

MenuBar — the MenuBar itself, useful for chaining.


addItem(item)

Add a new menu item to this MenuBar.

Parameters

NameTypeDescription
itemMenuItemthe item to add.

Return

MenuBar — the MenuBar itself, useful for chaining.


addItem(text, asHtml, command)

Creates a new menu item with the given text and command and adds it to this MenuBar.

Parameters

NameTypeDescription
textStringthe item text.
asHtmlBooleanwhether to treat the text as HTML.
commandHandlerthe ClientHandler or ServerHandler to execute when the menu is clicked.

Return

MenuBar — the MenuBar itself, useful for chaining.


addItem(text, asHtml, subMenu)

Creates a new menu item with the given text and submenu and adds it to this MenuBar.

Parameters

NameTypeDescription
textStringthe item text.
asHtmlBooleanwhether to treat the text as HTML.
subMenuMenuBarthe menu to show when this item is clicked.

Return

MenuBar — the MenuBar itself, useful for chaining.


addItem(text, command)

Creates a new menu item with the given text and command and adds it to this MenuBar.

Parameters

NameTypeDescription
textStringthe item text.
commandHandlerthe ClientHandler or ServerHandler to execute when the menu is clicked.

Return

MenuBar — the MenuBar itself, useful for chaining.


addItem(text, subMenu)

Creates a new menu item with the given text and submenu and adds it to this MenuBar.

Parameters

NameTypeDescription
textStringthe item text.
subMenuMenuBarthe menu to show when this item is clicked.

Return

MenuBar — the MenuBar itself, useful for chaining.


addSeparator()

Add a separator to the MenuBar.

Return

MenuBar — the MenuBar itself, useful for chaining.


addSeparator(separator)

Add a separator to the MenuBar.

This takes a MenuItemSeparator that has its own controllable properties, such as setVisible(), and can therefore be manipulated in code.

Parameters

NameTypeDescription
separatorMenuItemSeparatorthe separator to add.

Return

MenuBar — the MenuBar itself, useful for chaining.


addStyleDependentName(styleName)

Sets the dependent style name of this MenuBar.

This is useful for debugging but is otherwise of minimal use since there is no way to use custom stylesheets in UiApp.

Parameters

NameTypeDescription
styleNameStringthe new style name.

Return

MenuBar — the MenuBar itself, useful for chaining.


addStyleName(styleName)

Adds a style name to this MenuBar.

This is useful for debugging but is otherwise of minimal use since there is no way to use custom stylesheets in UiApp.

Parameters

NameTypeDescription
styleNameStringthe new style name.

Return

MenuBar — the MenuBar itself, useful for chaining.


getId()

Returns the id that has been assigned to this object.

This can be used in conjunction with app.getElementById() to retrieve a reference to this object.

Return

String — the id that has been assigned to this object


getTag()

Gets the text tag of this MenuBar.

Return

String — the text tag.


getType()

Gets the type of this object.

Return

String — the object type


setAnimationEnabled(animationEnabled)

Sets whether opening and closing the MenuBar is animated.

Parameters

NameTypeDescription
animationEnabledBooleanwhether to animate opening and closing.

Return

MenuBar — the MenuBar itself, useful for chaining.


setAutoOpen(autoOpen)

Sets whether this menu bar's child menus will open when the mouse is moved over it.

Parameters

NameTypeDescription
autoOpenBooleanwhether to open when the mouse is over the MenuBar.

Return

MenuBar — the MenuBar itself, useful for chaining.


setHeight(height)

Sets the height of this MenuBar.

Parameters

NameTypeDescription
heightStringthe new height in any CSS unit such as "10px" or "50%".

Return

MenuBar — the MenuBar itself, useful for chaining.


setId(id)

Sets the id of this MenuBar.

Parameters

NameTypeDescription
idStringthe new id, which can be used to retrieve the MenuBar from app.getElementById(id).

Return

MenuBar — the MenuBar itself, useful for chaining.


setPixelSize(width, height)

Sets the size of this MenuBar in pixels.

Parameters

NameTypeDescription
widthIntegerthe new width in pixels.
heightIntegerthe new height in pixels.

Return

MenuBar — the MenuBar itself, useful for chaining.


setSize(width, height)

Sets the size of this MenuBar.

Parameters

NameTypeDescription
widthStringthe new width in any CSS unit such as "10px" or "50%".
heightStringthe new height in any CSS unit such as "10px" or "50%".

Return

MenuBar — the MenuBar itself, useful for chaining.


setStyleAttribute(attribute, value)

Sets one of this MenuBar's style attributes to a new value. Valid attributes are listed here; the values for each attribute are the same as those available in CSS style sheets.

 
// Change the widget's background to black and text color to green.
 widget.setStyleAttribute("background", "black")
     .setStyleAttribute("color", "green");
 

Parameters

NameTypeDescription
attributeStringthe CSS attribute, in camel-case ("fontSize", not "font-size"), as listed here
valueStringthe CSS value

Return

MenuBar — the MenuBar itself, useful for chaining.


setStyleAttributes(attributes)

Sets this MenuBar's style attributes. This is a convenience method that is equivalent to calling setStyleAttribute with every key/value pair in the attributes object. Valid attributes are listed here; the values for each attribute are the same as those available in CSS style sheets.

 
// Change the widget's background to black and text color to green.
 widget.setStyleAttributes({background: "black", color: "green"});
 

Parameters

NameTypeDescription
attributesObjectan object of key/value pairs for the CSS attributes and values to set; valid attributes are listed here

Return

MenuBar — the MenuBar itself, useful for chaining.


setStyleName(styleName)

Sets the style name of this MenuBar.

This is useful for debugging but is otherwise of minimal use since there is no way to use custom stylesheets in UiApp.

Parameters

NameTypeDescription
styleNameStringthe new style name.

Return

MenuBar — the MenuBar itself, useful for chaining.


setStylePrimaryName(styleName)

Sets the primary style name of this MenuBar.

This is useful for debugging but is otherwise of minimal use since there is no way to use custom stylesheets in UiApp.

Parameters

NameTypeDescription
styleNameStringthe new style name.

Return

MenuBar — the MenuBar itself, useful for chaining.


setTag(tag)

Sets the text tag of this MenuBar.

Parameters

NameTypeDescription
tagStringthe new text tag, which can be anything you wish to store with the widget.

Return

MenuBar — the MenuBar itself, useful for chaining.


setTitle(title)

Sets the hover title of this MenuBar.

Not all browsers will show this.

Parameters

NameTypeDescription
titleStringthe hover title.

Return

MenuBar — the MenuBar itself, useful for chaining.


setVisible(visible)

Sets whether this MenuBar is visible.

Parameters

NameTypeDescription
visibleBooleanwhether this MenuBar should be visible or not.

Return

MenuBar — the MenuBar itself, useful for chaining.


setWidth(width)

Sets the width of this MenuBar.

Parameters

NameTypeDescription
widthStringthe new width in any CSS unit such as "10px" or "50%".

Return

MenuBar — the MenuBar itself, useful for chaining.

Deprecated methods

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.