# jEdit 2.6 User's Guide

Next, Prev

## Chapter 11. Developing Plugins

# The Plugins Menu

When a view is created, it queries all installed plugins for any menus and menu items they want to add to the Plugins menu.

While creating new `JMenuItem` and `JMenu` instances with hardcoded labels might seem like the easy way out, in reality it is not a good idea because the resulting plugin is inflexible and not easily localizable. This chapter describes how to do it the jEdit way.

#### EditPlugin.createMenuItems() method

    import java.util.Vector;

``void createMenuItems`(Vector menuItems);`

Newly created views call this method of each plugin in turn. The default implementation does nothing, but most plugins will want to override it to add instances of `javax.swing.JMenu` and `javax.swing.JMenuItem` to the menu item vector. While you could create instances of `JMenu` and `JMenuItem` directly, the preferred way is to use the methods of the `GUIUtilities` class.

#### GUIUtilities.loadMenu() method

    import javax.swing.JMenu;
    import org.gjt.sp.jedit.GUIUtilities;

``public static JMenu loadMenu`(String name);`

The `loadMenu()` method loads a menu from the properties. It obtains the menu from the following properties:

- `name`.label: the menu label, as it will appear in the Plugins menu

- `name`: a whitespace separated list of action names that are to appear in the menu. A dash ("-") in the list will insert a menu separator

#### GUIUtilities.loadMenuItem() method

    import javax.swing.JMenuItem;
    import org.gjt.sp.jedit.GUIUtilities;

``public static JMenuItem loadMenuItem`(String name);`

The `loadMenuItem()` loads a menu item from the properties. It is bound to the action named `name`, and the menu item label is loaded from the property named `name`.label.

#### Example

Here is a simple `createMenuItems()` method, place it in the `HelloWorldPlugin.java` source file and see what happens:

    public void createMenuItems(Vector menuItems)
    {
            menuItems.addElement(GUIUtilities.loadMenuItem("hello-world"));
    }

> Note: While you might be tempted to assign keyboard shortcuts to your plugin's actions, doing so is highly discouraged, for several reasons. First of all, if two plugins bind to the same key, nothing good will happen. Secondly, future jEdit versions might use your shortcuts. It is much better to let the user decide which plugins they actually use, and assign whatever shortcuts they want to them.

Home, Up
Prev: Plugin Actions
Next: The Global Options Dialog Box