Simple Menu Bars

In this section, we'll see how to create a menu bar with menus on it.

Creating a Menu

XUL has a number of different ways of creating menus. The most basic way is to add a menu bar with a row of menus on it like many applications have. You can also create popup menus. The menu features of XUL consist of a number of different elements which allow you to create menu bars or popup menus. The items on the menus can be customized quite easily. We've already seen part of how to make menus using the ref_menulistmenulist This section will build on that.

Menu bars are usually created much like a toolbar. The menu bar can be placed inside a ref_toolboxtoolbox and a grippy will appear on its left side so that it can be collapsed. The menu would work just like any other toolbar. XUL does have some special menu elements which provide special functionality typical of menus.

There are five elements associated with creating a menu bar and its menus, which are explained briefly here and in detail afterwards:

You can customize the menus on the menubar to have whatever you want on them on all platforms except the Macintosh. This is because the Macintosh has its own special menu along the top of the screen controlled by the system. Although you can create custom menus, any special style rules or non-menu elements that you place on a menu may not be applied. You should keep this is mind when creating menus.

Here is an example of a simple menu bar:

Example 5.1.1: /ex_5_1_1.xul.txt'>Source
<toolbox flex1 <menubar idsample-menubar <menu idfile-menulabelFile <menupopup idfile-popup <menuitem labelNew/ <menuitem labelOpen/ <menuitem labelSave/ <menuseparator/ <menuitem labelExit/ </menupopup </menu <menu idedit-menulabelEdit <menupopup idedit-popup <menuitem labelUndo/ <menuitem labelRedo/ </menupopup </menu </menubar </toolbox

Here, a simple menu bar is created using the ref_menubarmenubar element. It will create a row for menus to be placed on. Two menus, File and Edit have been created here. The ref_menumenu element creates the title at the top of the menu, which appears on the menu bar. The popups are created using the ref_menupoupmenupoup element. It will pop up when the user clicks on the parent menu title. The size of the popup will be large enough to fit the commands inside it. The commands themselves are created using the ref_menuitemmenuitem element. Each one represents a single command on the menu popup.

You can also create separators on the menus using the ref_menuseparatormenuseparator element. This is used to separate groups of menuitems.

The menubar is a box containing menus. Note that it has been placed inside a flexible ref_toolboxtoolbox The menubar has no special attributes but it is a type of box. This means that you could create a vertical menubar by setting the orient attribute to vertical.

The ref_menumenu element is normally placed on a menubar, although it does not have to be. However, it will be given a different look. The image here shows what the earlier example would look like without the menu bar.

The ref_menumenu element works much like the ref_buttonbutton element. It accepts some of the same attributes plus some additional ones:

The ref_menupopupmenupopup element creates the popup window containing the menu commands. It is a type of box which s to a vertical orientation. You could change it to horozontal if you wanted to and the menuitems would be placed in a row. Normally only menuitems and menuseparators would be placed on a ref_menupopupmenupopup You can place any element on a ref_menupopupmenupopup, however they will be ignored on a Macintosh.

The ref_menuitemmenuitem element is much like the ref_menumenu element and has some of the same attributes.

The ref_menuseparatormenuseparator has no special attributes. It just creates a horizontal bar between the menuitems next to it.



Bhopal news
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100

freelance web designer india ecommerce web developer | Ecommerce web design, software developer india | Web hosting India Windows hosting | India web hosting Windows hosting India | India software developer | web designer india