Add a submenu

Eduardo Ramos edited this page Jan 7, 2015 · 2 revisions
Clone this wiki locally

From a plugin it is easy to add a menu in the menubar, for instance in Plugins. If you wanna add your action in a already existing menu, like Generate, don't follow this HowTo but look more how to create a new Generator, as the submenus may be created dynamically.

Create Action and Menu

  • Step 1: Right click on your module and select New > Other... and find Action like showed in the step 1 below. The action wizard will create everything necessary to register your action in the system and create the submenu.

addsubmenu-new-action

  • Step 2: Then click on Next, be sure Always Enabled is checked and Next again.
  • Step 3: In the Menu option, select where you want your submenu to be put. Select Plugins to be put in this menu.

addsubmenu-new-action-gui

  • Step 4: Click on Next and fill the class name, as well as the display name.

addsubmenu-new-action-name

  • Step 5: Finally, click on Next to create the file.

addsubmenu-new-action-result

Result

Fill Action

The precedent step created the MyAction.java file in your module. Implement something in the action to be executed when users click on the menu. In the example below an empty dialog is showed, using Dialogs API. Include Dialogs API as a dependency of your module if you want to use it.

public final class MyAction implements ActionListener {

   public void actionPerformed(ActionEvent e) {
      //Do something - for instance display a dialog
      DialogDescriptor dd = new DialogDescriptor(new JPanel(), "My Dialog", false, null);
      DialogDisplayer.getDefault().notify(dd);
   }
}