J2ME Polish
J2ME Polish 2.4 Documentation
Enough Software

Using Alerts

Notify your user about errors or finished tasks with Alerts.
showing an alert as popup


The above design has been realized with following CSS code:

.mailForm {
	padding: 5;
	padding-left: 5;
	padding-right: 5;
	background-color: black;
	layout: horizontal-expand | horizontal-center | top;
	//#if !polish.useScrollBar
		scrollindicator-up-image: url( arrowUp.png );
		scrollindicator-down-image: url( arrowDown.png );
	//#if polish.midp2
		screen-change-animation: fade;
	//#if polish.api.mmapi
		title-style: .mailFormTitle;

.mailAlert extends .mailForm {
	title-style: none;
	margin-right: 10;
	margin-left: 10;
	padding-left: 5;
	padding-right: 5;
	layout: horizontal-center | bottom | horizontal-shrink | vertical-shrink;
	repaint-previous-screen: true;
	//#if polish.midp2 || polish.api.nokia-ui
		border {
			type: drop-shadow;
			width: 6;
			inner-color: #aff0;
			outer-color: #2002;
			orientation: top-right;
	//#if polish.midp2
		screen-change-animation: fade;
	background-color: green;

alertcontent {
	font-color: white;


import de.enough.polish.ui.Alert;
import de.enough.polish.ui.AlertType;
//#style mailAlert
Alert alert = new Alert("Exit?", "Do you really want to exit?", null, AlertType.CONFIRMATION);
final Command cmdYes = new Command("Yes", Command.OK, 1);
final Command cmdNo = 	new Command("No", Command.CANCEL, 1);
alert.setCommandListener(new CommandListener() {
	public void commandAction(Command c, Displayable d) {
		if (c == cmdYes) {
		} else {

Alert CSS Attributes

You can use the following CSS attributes for the Alert:

alertcontent CSS Attributes

Use the predefined style alertcontent for designing the text and optional image of the alert or select a custom style using the content-style CSS attribute.
You can use all settings that are available for the IconCustomItem for the Alert's content as well:


Use a alert as you would use a normal javax.microedition.lcdui.Alert in your application and use UiAccess for using J2ME Polish specific functionalities like:

  • setStyle( Alert alert ): Sets a style in conjunction with a style preprocessing directive.
  • setStyle( Alert alert, Style style ): Sets a style programmatically.

Configuration: Use Buttons instead of Commands

You can use buttons instead of commands for Alerts which makes selecting options much easier on touch enabled phones. For this to work you need these two preprocesing configuration variables in your build.xml script defined:

	<variable name="polish.Item.suppressDefaultCommand" value="true" />
	<variable name="polish.Alert.useButtonsForCommands" value="true" />

For the buttons the style .alertButton along with its :hover and :pressed styles is used, if defined.
Alternatively you can use the #style preprocessing directive when adding a command to an Alert:

//#style messageAlert
Alert alert = new Alert( "Alert", "My message", null, AlertType.INFO );
alert.setTimeout( Alert.FOREVER );
alert.addCommand( new Command( "default", Command.OK, 1)); // here the .alertButton style is being used...
//#style alertButton2
alert.addCommand( new Command( "custom", Command.SCREEN, 2));

In your polish.css you have to define these styles:

.alertButton {
	font-color: #666;

.alertButton:hover {
	border-color: #000;
	font-color: #000;

.alertButton:pressed {
	border-color: #000;
	background-color: #333;
	font-color: #fff;

.alertButton2 {
	font-color: #333;

.alertButton2:hover {
	border-color: #f00;
	font-color: #f00;

.alertButton2:pressed {
	border-color: #f00;
	font-color: #fff;
	background-color: #a00;

Configuration: Native Alerts

On JavaME, BlackBerry and Android platforms you can use native Alerts, which is highly recommended for BlackBerry, Android and Nokia Asha platforms. Just define the polish.useNativeAlerts preprocessing variable in your build.xml script:

	<variable name="polish.useNativeAlerts" value="true" if="polish.blackberry or polish.android or (polish.NokiaUiApiVersion >= 1.1)" />	


You translate the default dismiss command of an Alert without timeout using the variables section of your build.xml script or the messages.txt file. Refer to the localization documentation for more details on this.

# sets the text of an Alert's dismiss command (default=OK):


back to top