Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

FAQ How do I add actions to a view's menu and toolbar?

Each view has a drop-down menu in two locations:

  • under the icon on the view's tab item.

This menu contains layout and view-manipulation actions. You don't have any control over this menu; its actions are all added by the platform.


  • in the view's toolbar.

The drop-down menu on the right-hand side, a small downward-pointing triangle, is controlled by your view. This menu will exist only if you add actions to it.


Actions are added to the menu and toolbar by using the IActionBars interface. This interface is used to access the standard JFace menu and toolbar manager objects used for creating menus throughout Eclipse. The following code, usually invoked from the view's createPartControl method, adds a single action to the view's menu and toolbar:

   Action action = ...;
   IActionBars actionBars = getViewSite().getActionBars();
   IMenuManager dropDownMenu = actionBars.getMenuManager();
   IToolBarManager toolBar = actionBars.getToolBarManager();
   dropDownMenu.add(action);
   toolBar.add(action);
   actionBars.updateActionBars();


See Also:

FAQ How do I build menus and toolbars programmatically?


This FAQ was originally published in Official Eclipse 3.0 FAQs. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the Eclipse Public License v1.0.

Back to the top