How to create a JMenu

We use the JFrame created before to supply it with a new File Menu. First we have to select the frame in the components tree. Now we select new JMenuBar from the toolbar and save the properties as explained before. Then we select this new Component in the tree and select new JMenu from the toolbar.

Check the box Text and set the property to File.

Check the box Mnemonic and set the property to f. Save the newly created JMenu and select it in the tree.

Repeat four times to select new JMenuItem from the toolbar and set the following properties:

Name Text Mnemonic CP ( classpath ) Icon
mnNew New n checked /toolbarButtonGraphics/general/New16.gif
mnOpen Open o checked /toolbarButtonGraphics/general/Open16.gif
mnClose Close c checked /toolbarButtonGraphics/general/Export16.gif
mnExit Exit x unchecked

Save all your properties data, select the frame in the tree and check it with the button from the toolbar. As you can see you have a ready-to-use menu.

Now I want to show you how to use the Move Up Component and Move Down Component button. As we want to separate the Exit menu item from the rest of the File menu items we select the JMenu in the tree and create a new JSeparator. When you save this Component it is added to the tree, but it is the last one in the menu. This is not what we want, so we select the newly created separator in the tree and press the Move Up Component button. To see the result, select the frame again and check it.