Menubar & Menu Design
J2ME Polish allows you to choose between 3 different options for realizing the menu:
- Default Menu: The default menu uses a structure similar to Nokia implementations and offers the same look and feel on all devices.
- Extended Menu: The extended menu offers additional design options and provides device dependent implementations, so that the "feel" does not differ from native menus. This brings an overhead of around 2kb for the JAR size.
- Native Menu: The native menu uses the device-dependent implementation, which provides the best native integration but no design options at all.
Default Menu
Design of the Default Menubar
The default menubar uses a structure similar to Nokia implementations and offers the same look and feel on all devices.
![]()
The above design has been realized with these polish.css and build.xml settings:
polish.css:
colors {
fontColor: #333;
}
menu {
font-color: fontColor;
font-style: bold;
menubar-color: yellow;
}
build.xml:
<variable name="polish.MenuBar.PaddingLeft" value="5" />
<variable name="polish.MenuBar.PaddingRight" value="5" />
<variable name="polish.MenuBar.PaddingTop" value="5" />
<variable name="polish.MenuBar.PaddingBottom" value="1" />
The font of the default menubar is defined in the "menu" style, which is also responsible for the command popup screen. Additionally you can specify the menubar-color in either the "menu" style or in the corresponding screen's style:
| CSS Attribute | Default | Values | Applies To | Explanation |
|---|---|---|---|---|
| menubar-color | white | color or transparent | menu or screen's style |
The color of the menubar. You might want to set it to transparent when using an image screen background. |
| font-color | black | color definition | menu style |
The color of the menubar font. |
| font-size | medium | small, medium, large | menu style |
The size of the menubar font. |
| font-style | plain | plain, bold, italic, underlined | menu style |
The style of the menubar font. |
Configuration of the Default Menubar
The default menu has to be activated by setting the "fullscreen" attribute of the <build> element to true in your build.xml script:
<build usePolishGui="true" fullscreen="menu" ...>
Alternatively you can set the "polish.useMenuFullScreen" variable to true:
<variable name="polish.useMenuFullScreen" value="true" />
You can specify the used paddings between the screen's border and the default menubar by defining "polish.MenuBar.PaddingLeft" etc:
<variable name="polish.MenuBar.PaddingLeft" value="3" /> <variable name="polish.MenuBar.PaddingRight" value="3" /> <variable name="polish.MenuBar.PaddingTop" value="3" /> <variable name="polish.MenuBar.PaddingBottom" value="3" />
Extended Menubar
Design of the Extended Menubar
The extended menubar offers some additional design options and provides device dependent implementations, so that the "feel" does not differ from native menus.
You can use any backgrounds for the extended menubar:
![]()
It's also possible to use advanced text designs like the shadow text-effect for the extended menubar:

The above design has been realized with these polish.css settings:
colors {
fontColor: #333;
}
/** The extended menu bar */
menubar
{
margin: 0;
padding: 2;
padding-top: 3;
background {
type: vertical-gradient;
top-color: #ccc;
bottom-color: #fff;
start: 10%;
end: 90%;
}
}
/**
* Commands within the extended menubar on the left side
*/
leftcommand
{
margin: 0;
padding-top: 3;
padding-bottom: 0;
font-color: fontColor;
font-style: bold;
text-effect: shadow;
text-shadow-color: #ff0;
}
/**
* Commands within the extended menubar on the right side
*/
rightcommand extends leftcommand
{
layout: right;
}
The background, paddings, margins and borders of the menubar are designed within the menubar style. Note that the CSS attribute menubar-color has
no effect, when using the extended menubar, as you can now use any background. The text on the left side within the menubar is
designed with the leftcommand, the one on the right side accordingly with the rightcommand style.
| CSS Attribute | Default | Values | Explanation | Since |
|---|---|---|---|---|
| leftcommand-style | - | style | The style for the command shown on the left side of the menubar. can only be used when the extended menubar is enabled. | 2.0 |
| menu-style | - | style | The style for the commands within the options command of the menubar. Can only be used when the extended menubar is enabled. | 2.0 |
| menubar-cancel-image | - | imageurl | Defines the image-URL for the cancel-image of the extended menubar. | 1.3 |
| menubar-options-image | - | imageurl | Defines the image-URL for the options-image of the extended menubar. | 1.3 |
| menubar-select-image | - | imageurl | Defines the image-URL for the select-image of the extended menubar. | 1.3 |
| menubar-show-image-and-text | false | true, false | Determines whether the text should also be shown in the menubar, when an image has been defined for the corresponding action. | 1.3 |
| middlecommand-style | - | style | The style for the (item) command shown in the middle of the menubar. Can only be used when the extended menubar is enabled. | 2.0 |
| rightcommand-style | - | style | The style for the command shown on the right side of the menubar. Can only be used when the extended menubar is enabled. | 2.0 |
| Further CSS Attribute | Default | Values | Explanation | Since |
| after | - | imageurl | The URL of the image that should be shown after the item in question. | 1.3 |
| always-include | false | true, false | Defines if a style should always be included, even if not used. This is useful for programmatically accessed and for HTML browser styles. | 2.0 |
| background | - | background definition | The background of an item or screen. The default background for items is "none", the default background for screens is a simple white background. | 1.0 |
| background-anchor | left | top | left, horizontal-center, h-center, hcenter, center, right, top, vertical-center, v-center, vcenter, bottom | The orientation of the background in case either it's width or height is different from the item's dimensions. | 2.1 |
| background-height | 0px | dimension (px, %), e.g. 3.5% | The height of the background in pixel or percent, if it should differ from the the item's width. | 2.1 |
| background-width | 0px | dimension (px, %), e.g. 3.5% | The width of the background in pixel or percent, if it should differ from the the item's width. | 2.1 |
| before | - | imageurl | The URL of the image that should be shown before the item in question. | 1.3 |
| bgborder | - | border | The border of an item which is painted before the background. This needs to be a reference to a border defined in the borders section. | 2.1 |
| complete-border | - | border | A border reference from the borders section. The border includes the label of the item and is independent of the item's normal border. | 2.0 |
| border | - | border definition | The border of an item or screen. The default border is "none". | 1.0 |
| colspan | 1 | integer | The number of columns wich are used by the item within a table. | 1.3 |
| complete-background | - | background | A background name from the backgrounds section. The background includes the label of the item and is independent of the item's normal background. | 1.3 |
| complete-background-padding | - | integer | The padding that is added to the complete-background and/or complete-border. Note that this does not change the size of the item, so you might need to adapt margins or normal paddings for your design. | 2.0 |
| content-visible | true | true, false | Activates or deactives the visibility of the item's contents. When the content is not visible, only the label as well as before and after attributes are visible. | 2.1 |
| content-x-adjust | 0px | dimension (px, %), e.g. 3.5% | The horizontal position adjustment of an item's content, use a negative value to move it to the left. | 2.1 |
| content-y-adjust | 0px | dimension (px, %), e.g. 3.5% | The vertical position adjustment of an item's content, use a negative value to move it to the top. | 1.3 |
| filter | - | Defines a filter for the specified UI element. | 2.1 | |
| focused-style | focused | style | The name of the style for the currently focused item, usually applied with a [style-name]:hover construct. | 1.0 |
| include-label | false | true, false | Usually the label of an item is rendered separately of the item's content. You can expand the background and border over the label as well using this attribute. | 1.3 |
| inherit | true | true, false | Defines if a style that extends this style should inherit all attributes. | 1.3 |
| inline-label | false | true, false | Inlines the label of an item, so that the content will be on the same row (or at least start on the same row). The label can only occupy 90% or less of the available width, otherwise this setting is ignored. | 2.1 |
| label-style | label | style | The name of the style for the label of the corresponding Item. | 1.0 |
| max-height | - | dimension (px, %), e.g. 3.5% | The maximum height of an item. | 1.3 |
| max-width | - | dimension (px, %), e.g. 3.5% | The maximum width of an item. | 1.3 |
| min-height | - | dimension (px, %), e.g. 3.5% | The minimum height of an item. | 1.3 |
| min-width | - | dimension (px, %), e.g. 3.5% | The minimum width of an item. | 1.3 |
| opacity | 100% | dimension (px, %), e.g. 3.5% | The opacity of an item between 0 (fully transparent) and 100% / 255 (fully opaque). | 1.3 |
| pressed-style | - | style | The style which indicates that an item is being pressed, usually applied with a [style-name]:pressed construct. | 2.0 |
| view-type | - | fade-in, fade-out, particle, size-decrease, size-increase | Defines another visualization for an Item or a Screen. | 1.3 |
| visible | true | true, false | Toggles the visibility of an item. When an item is invisible, it will not occupy any space. | 2.0 |
| x-adjust | 0px | dimension (px, %), e.g. 3.5% | The horizontal position adjustment of an item, use a negative value to move it to the left. | 2.1 |
| y-adjust | 0px | dimension (px, %), e.g. 3.5% | The vertical position adjustment of an item, use a negative value to move it to the top. | 2.1 |
Following further CSS attributes can be used to adjust the menubar design:
| CSS Attribute | Default | Values | Applies To | Explanation |
|---|---|---|---|---|
| overlay | #a000 | ARGB color definition | colors section |
When the extended menubar is opened, it will dim the screen's contents with the overlay color defined within the
colors section of your polish.css file.
colors {
/* create a white translucent overlay: */
overlay: argb( 80, 255, 255, 255 );
}
|
| overlay-background | - | Reference to background defined in the backgrounds section. | Screens | You can also defined a screen specific overlay background. |
| menubar-style | menubar | style reference | screen's style | Changes the style of the menubar for the affected screens. |
For the design options for leftcommand and rightcommand, please refer to the design guide for
StringItem.
Configuration of the Extended Menubar
The extended menubar has to be activated in your build.xml script by setting the "polish.MenuBar.useExtendedMenuBar" to "true":
<variable name="polish.MenuBar.useExtendedMenuBar" value="true" />
Additionally the general usage of the menu has to be activated by setting the "fullscreen" attribute of the <build> element to true in your build.xml script:
<build usePolishGui="true" fullscreen="menu" ...>
Alternatively you can set the "polish.useMenuFullScreen" variable to true:
<variable name="polish.useMenuFullScreen" value="true" />
You can specify the positioning of the menu for the extended menubar by setting the appropriate preprocessing variables:
<variable name="polish.MenuBar.OptionsPosition" value="left" /> <variable name="polish.MenuBar.OkPosition" value="left" />
Menu
Designing the Menu
When you have activated the default or the extended menubar, you can also design your menu using the menu and menuitem
styles in your polish.css file.
When the menu is opened (and you use the extended menubar), the shown screen will be dimmed by painting the screen with a translucent overlay color,
if the device supports translucency. The default overlay color is argb( 136, 0, 0, 0 ), you can specify it differently within the
colors section of your polish.css file:

colors {
overlay: argb( 136, 0, 0, 0 );
}
menu {
margin-left: 4;
margin-right: 4;
margin-bottom: -4; /* for the border */
min-width: 100;
padding: 2;
font-color: focusedFontColor;
font-size: small;
view-type: slide-up;
border {
type: drop-shadow;
width: 4;
start-color: #aeee;
end-color: #2222;
orientation: top-right;
}
background {
type: horizontal-stripes;
first-top-color: screenColorTop1;
first-bottom-color: screenColorBottom1;
second-top-color: screenColorTop2;
second-bottom-color: screenColorBottom2;
}
}
/**
* The menuItem style is a predefined style
* for the actual commands in a fullscreen-menu.
* When the menuItem style is not defined,
* the menu style will be used instead.
*/
menuItem {
padding: 3;
padding-left: 10;
padding-right: 10;
font {
color: fontColor;
size: small;
style: bold;
}
layout: left;
//#if ${ exists( arrowRight.png ) }
command-child-indicator: url(arrowRight.png);
//#else
command-child-indicator-color: blue;
command-child-indicator-width: 8;
command-child-indicator-height: 10;
//#endif
}
.menuItem:hover {
padding: 2;
padding-left: 9;
padding-right: 9;
background {
type: round-rect;
color: focusedBackgroundColor;
border-color: focusedBorderColor;
}
font {
style: bold;
size: small;
color: focusedFontColor;
}
layout: left | horizontal-expand;
}
All comand- / menu-items do support normal text design. Additionally you can design the indicators that show the availability of subcommands with
the child-indicator CSS attributes:
| CSS Attribute | Default | Values | Explanation | Since |
|---|---|---|---|---|
| command-child-indicator | - | imageurl | The image used for a command to indicate that it has subcommands. | 1.3 |
| command-child-indicator-color | - | color | The color for the drawn arrow that is used for a command to indicate that it has subcommands. Only used when the "command-child-indicator" CSS attribute is not set. | 1.3 |
| command-child-indicator-height | - | integer | The height of the drawn arrow that is used for a command to indicate that it has subcommands. Only used when the "command-child-indicator" CSS attribute is not set. | 1.3 |
| command-child-indicator-width | - | integer | The width of the drawn arrow that is used for a command to indicate that it has subcommands. Only used when the "command-child-indicator" CSS attribute is not set. | 1.3 |
| suppress-indicator | false | true, false | suppresses the indicator of a CommandItem | 2.1 |
| Further CSS Attribute | Default | Values | Explanation | Since |
| after | - | imageurl | The URL of the image that should be shown after the item in question. | 1.3 |
| always-include | false | true, false | Defines if a style should always be included, even if not used. This is useful for programmatically accessed and for HTML browser styles. | 2.0 |
| background | - | background definition | The background of an item or screen. The default background for items is "none", the default background for screens is a simple white background. | 1.0 |
| background-anchor | left | top | left, horizontal-center, h-center, hcenter, center, right, top, vertical-center, v-center, vcenter, bottom | The orientation of the background in case either it's width or height is different from the item's dimensions. | 2.1 |
| background-height | 0px | dimension (px, %), e.g. 3.5% | The height of the background in pixel or percent, if it should differ from the the item's width. | 2.1 |
| background-width | 0px | dimension (px, %), e.g. 3.5% | The width of the background in pixel or percent, if it should differ from the the item's width. | 2.1 |
| before | - | imageurl | The URL of the image that should be shown before the item in question. | 1.3 |
| bgborder | - | border | The border of an item which is painted before the background. This needs to be a reference to a border defined in the borders section. | 2.1 |
| complete-border | - | border | A border reference from the borders section. The border includes the label of the item and is independent of the item's normal border. | 2.0 |
| border | - | border definition | The border of an item or screen. The default border is "none". | 1.0 |
| colspan | 1 | integer | The number of columns wich are used by the item within a table. | 1.3 |
| complete-background | - | background | A background name from the backgrounds section. The background includes the label of the item and is independent of the item's normal background. | 1.3 |
| complete-background-padding | - | integer | The padding that is added to the complete-background and/or complete-border. Note that this does not change the size of the item, so you might need to adapt margins or normal paddings for your design. | 2.0 |
| content-visible | true | true, false | Activates or deactives the visibility of the item's contents. When the content is not visible, only the label as well as before and after attributes are visible. | 2.1 |
| content-x-adjust | 0px | dimension (px, %), e.g. 3.5% | The horizontal position adjustment of an item's content, use a negative value to move it to the left. | 2.1 |
| content-y-adjust | 0px | dimension (px, %), e.g. 3.5% | The vertical position adjustment of an item's content, use a negative value to move it to the top. | 1.3 |
| icon-filter | - | filter | Specifies an RGB filter for the image of an icon item | 2.1 |
| filter | - | Defines a filter for the specified UI element. | 2.1 | |
| focused-style | focused | style | The name of the style for the currently focused item, usually applied with a [style-name]:hover construct. | 1.0 |
| font | none | object | The font reference for a StringItem, TextField, etc. | 1.0 |
| font-bitmap | - | string | Defines which bitmap (bmf) font should be used. | 1.3 |
| font-color | black | color | The font color of an item or screen element. | 1.0 |
| font-face | medium | system, default, normal, proportional, monospace | The font face of an item or screen element. | 1.0 |
| font-size | medium | small, little, medium, default, normal, large, big | The font size of an item or screen element. | 1.0 |
| font-style | plain | plain, default, normal, bold, italic, cursive, underlined, underline | The font style of an item or screen element. | 1.0 |
| force-lines | - | true, false | forces the StringItem to display the lines stated in max-lines | 2.1 |
| icon-horizontal-adjustment | 0 | integer | Adjusts the icon by the specified number of pixels horizontally. Negative values move the icon-image to the left. | 1.3 |
| icon-image | none | imageurl | The URL of the image. The keyword %INDEX% can be used for adding the position of the icon to the name, e.g."icon-image: url(icon%INDEX%.png);". | 1.0 |
| icon-image-align | left | left, right, top, bottom, center | The position of the image relative to the text. | 1.0 |
| icon-image-align-next | false | true, false | Specifies if a horizontal aligned image should be painted at the border (=default) or next to the content when the item has an expand layout. | 2.0 |
| icon-inactive | false | true, false | Can be used to deactivate a specific ChoiceGroup/List item permanently. This can be useful to integrate explanations, headings etc into an ChoiceGroup/List. | 1.3 |
| icon-padding | 1 | integer | The padding between the image and the text of an icon. | 2.0 |
| icon-vertical-adjustment | 0 | integer | Adjusts the icon by the specified number of pixels vertically. Negative values move the icon-image to the top. | 1.3 |
| include-label | false | true, false | Usually the label of an item is rendered separately of the item's content. You can expand the background and border over the label as well using this attribute. | 1.3 |
| inherit | true | true, false | Defines if a style that extends this style should inherit all attributes. | 1.3 |
| inline-label | false | true, false | Inlines the label of an item, so that the content will be on the same row (or at least start on the same row). The label can only occupy 90% or less of the available width, otherwise this setting is ignored. | 2.1 |
| label-style | label | style | The name of the style for the label of the corresponding Item. | 1.0 |
| max-height | - | dimension (px, %), e.g. 3.5% | The maximum height of an item. | 1.3 |
| max-lines | - | integer | the maximum lines to show in a stringitem | 2.1 |
| max-width | - | dimension (px, %), e.g. 3.5% | The maximum width of an item. | 1.3 |
| min-height | - | dimension (px, %), e.g. 3.5% | The minimum height of an item. | 1.3 |
| min-width | - | dimension (px, %), e.g. 3.5% | The minimum width of an item. | 1.3 |
| text-layout | left | top | left, horizontal-center, h-center, hcenter, center, right, top, vertical-center, v-center, vcenter, bottom, horizontal-expand, h-expand, hexpand, expand, vertical-expand, v-expand, vexpand, horizontal-shrink, h-shrink, hshrink, vertical-shrink, v-shrink, vshrink, newline-after, newline-before | The layout of the text, this is useful in combination with min-width or max-width and an item layout that differs from the desired text layout. | 2.1 |
| opacity | 100% | dimension (px, %), e.g. 3.5% | The opacity of an item between 0 (fully transparent) and 100% / 255 (fully opaque). | 1.3 |
| pressed-style | - | style | The style which indicates that an item is being pressed, usually applied with a [style-name]:pressed construct. | 2.0 |
| scale-factor | - | integer | The factor in percent by which the image should be scaled, e.g. 200. | 1.3 |
| scale-steps | 5 | integer | The number of intermediate steps that should be used for scaling an image. | 1.3 |
| text-effect | - | Sets a text effect. | 1.3 | |
| text-horizontal-adjustment | 0 | integer | Adjusts the text by the specified number of pixels horizontally. Negative values move the text to the left. | 1.3 |
| text-vertical-adjustment | 0 | integer | Adjusts the text by the specified number of pixels vertically. Negative values move the text to the top. | 1.3 |
| text-visible | true | true, false | Set the text of an IconItem to visible or invisible | 2.1 |
| text-wrap | true | true, false | Determines wether the text should be wrapped or whether it should be kept on a single line, even when it is larger than the available width. | 1.3 |
| text-wrap-animate | true | true, false | You can deactivate animations for texts that should not be wrapped and which are too long for a single line. | 2.0 |
| text-wrap-animation-direction | both | both, left, right | The direction of the animation when the text is too wide and wrapping is deactivated. | 2.0 |
| text-wrap-animation-speed | 1 | integer | The speed of the animation when the text is too wide and wrapping is deactivated. | 2.0 |
| view-type | - | fade-in, fade-out, particle, size-decrease, size-increase | Defines another visualization for an Item or a Screen. | 1.3 |
| visible | true | true, false | Toggles the visibility of an item. When an item is invisible, it will not occupy any space. | 2.0 |
| x-adjust | 0px | dimension (px, %), e.g. 3.5% | The horizontal position adjustment of an item, use a negative value to move it to the left. | 2.1 |
| y-adjust | 0px | dimension (px, %), e.g. 3.5% | The vertical position adjustment of an item, use a negative value to move it to the top. | 2.1 |
Animating the Menu
You can use any animation for animating the menu. A commonly used animation is the "slide-up" animation, that scrolls the menu upwards when the user opens the menu:
menu {
margin-left: 4;
margin-right: 4;
margin-bottom: -4; /* for the border */
min-width: 100;
padding: 2;
font-color: focusedFontColor;
font-size: small;
view-type: slide-up;
border {
type: drop-shadow;
width: 4;
start-color: #aeee;
end-color: #2222;
orientation: top-right;
}
background {
type: horizontal-stripes;
first-top-color: screenColorTop1;
first-bottom-color: screenColorBottom1;
second-top-color: screenColorTop2;
second-bottom-color: screenColorBottom2;
}
}
Configuration of the Menu
The position of the menu is defined within the device dabatase with following capabilities:
<capability name="MenuBar.OptionsPosition" value="right" /> <capability name="MenuBar.OkPosition" value="left" />
You can override the positioning of the menu for the extended menubar by setting the appropriate preprocessing variables:
<variable name="polish.MenuBar.OptionsPosition" value="left" /> <variable name="polish.MenuBar.OkPosition" value="left" />
Localization of the Menu
Since the menu implementation uses some texts like "Select" and "Cancel", you might want to localize or change these text. Please refer to the Localization Guide for detailed information. Following localization properties are used by the J2ME Polish Menu in the messages.txt file:
polish.command.ok=OK polish.command.cancel=Cancel polish.command.select=Select polish.command.options=Options
Programming
Styling Specific Commands
When adding commands or subcommands you can use the #style preprocessing directive for applying specialized styles:
Form form = new Form("Hello World");
//#style helloCommand
form.addCommand( this.cmdHello );
// using the default "menuitem" style:
form.addCommand( this.cmdExit );
You can add subcommands by calling UiAccess.addSubCommand( Command child, Command parent, Screen screen ):
//#style onlineCmd UiAccess.addSubCommand( this.cmdStatusOnline, this.cmdStatus, form ); // using the default "menuitem" style: UiAccess.addSubCommand( this.cmdStatusOffline, this.cmdStatus, form );
You can use the .menu1 style for designing the background and layout of the first layer of subcommands,
.menu2 for the second, and .menu3 for the third level of subcommands:
/** design the first level of subcommands: */
.menu1 extends menu {
background-color: #ddd;
}
Order Commands
The order of commands is specified using the priorities of commands. A command with a higher numerical value will be placed below a command with a lower value.
Deactivate Commands
You can deactivate specific commands by calling UiAccess.setAccessible( Screen screen, Command command, boolean accessible ):
//#style commandInactive UiAccess.setAccessible( myForm, cmdForward, false );
Please note that you need to use the extended menubar when you want to deactivate commands that are shown directly (not within the Options menu).