FAQs

Q: Why Display.init(Object m) is always called first before any Form is shown?

Before any Form is shown, the midlet must be registered. Display.init(Object m) method performs this task for you. It is a static method that creates a device-specific implementation class instance behind the scenes, and sets some parameters based on, for example, the number of softkeys and whether or not the device has a touch screen.

Q: Is it possible to apply Font on a Container?

No. It is not possible to apply a Font using style on a Container.

Q: How can I create and set a System font to a component?

You can create and apply font using following code:

Font font = Font.createSystemFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE);yourComponent.getStyle().setFont(font);

Q: How can I create and set a Bitmap font to a component?

Just use the bitmap font creation tools within LWUIT resource editor or Ant task to create a font and then set that font either via the theme or by manually extracting it from the resource file. Please see Developer Guide for detailed information.

Q: How can I align the text of a component?

You can apply alignment using following code:

yourComponent.getStyle().setAlignment(int align);

The align parameter can take values: Label.LEFT, Label.RIGHT or Label.CENTER

Q: How can I apply transparency to a component?

Lightweight UI Toolkit style supports background component transparency, to add flexibility and appeal to the UI. To set a component transparency level, call setBgTransparency and specify an integer or a byte. The integer value must range between 0 to 255, where 255 (the default) is opaque.

Q: Can I receive events from actionPerformed() on a TextArea/TextField?

No currently events through actionPerformed in not available on TextField/TextArea.

Q: How do i give a marquee effect to a Label?

Use method setFocusable(true) to give a marquee effect on the Label.

Q: How to make a CheckBox/RadioButton checked and disabled both?

You can make a CheckBox/RadioButton checked and disabled both by using setSelected(true) and setEnabled(false).

Q: What should I do for the performance issues with LWUIT?

First please check if the same problem exists on the demo applications available i.e. LWUITDemo, ContactBookDemo etc. If not then try to create the use case and investigate it.

Q: Can we hide the top header bar in LWUIT and make the application as full screen?

Yes this can be achieved by calling setForceFullScreen(true) method on the instance of current Display.

Q: I'm getting out of memory errors in LWUIT/LWUIT is consuming a lot of memory in my memory monitor?

Check that your application does not hold onto pointers for components, since a component references its parent component holding onto a single button can keep an entire form with all its content in memory... LWUIT allocates and discards frequently to allow for a small memory footprint, this causes the graph of free memory to fluctuate but the alternative of caching would be worse for highly constrained devices.

Q: Why my list/text area won't scroll/jumps around?

You need to disable the scrolling for the form using myForm.setScrollable(false) and you should place the list in a center of a border layout.

Q: How do I fix application freeze issues?

The application freeze may occur because of EDT violations.The EDT is the Event Dispatch Thread which encapsulates the platform specific event delivery and painting semantics and enables threading features such as animations etc... The EDT should not be blocked since paint operations and events would also be blocked in much the same way as they would be in other platforms. In order to serialize calls back into the EDT use the methods callSerially(java.lang.Runnable)and callSeriallyAndWait(java.lang.Runnable). The solution is to use threads for such long running tasks, however interaction with LWUIT can only be performed on the EDT. To return into the EDT you can use Display.callSerially/callSeriallyAndWait, a different option is to use invokeAndBlock.

Q: How do I reposition/resize a dialog?

Use a Dialog instance and a version of show which accepts 4 integer values to position the dialog. You can use the set the default dialog position to simplify dialog positioning.

Q: How do I show Video?

Use MMAPI to create a Player object which you can submit to the MediaComponent class.

Q: Can I create my own components?

Everything in LWUIT is fully extensible, you can derive from any component and extend it.

Q: I'm trying to display an animated gif and thats not working?

Animated gifs can be shown in MIDP using the MMAPI and MediaComponent (see the MMAPI question). LWUIT has special support for StaticAnimation which is a LWUIT specific format very similar to the animated gif. Both the resource editor and the ant task accept animated GIF files to create static animations.

Q: How to set different theme for different devices?

In LWUIT for Series 40, we have added methods to help developers set different themes for non-touch, touch & type and full touch.

    /**
     * Loads a theme from resource and applies it for defined device type.
     *
     * @param resRef a local reference to a resource using the syntax of
     * Class.getResourceAsStream(String)
     * @param deviceType device type as defined in Display class
     * @param themeId name of the theme resource
     */
    public void loadThemeForDeviceType(String resRef, int deviceType, String themeId)


	//example setting theme for full touch device
	UIManager.getInstance().loadThemeForDeviceType("/theme-file.res", Display.FULL_TOUCH_DEVICE, "NameOfTheme");

	//for the devices, we have flags in Display class
	Display.NON_TOUCH_DEVICE;
	Display.TOUCH_AND_TYPE_DEVICE;
	Display.FULL_TOUCH_DEVICE;
	Display.ASHA_DEVICE;

Q: How to set Bgcolor of a button?

Bgcolor of a button can be changed by:

Button b = new Button("");
Style style = new Style();
style.setBgTransparency(255);
style.setBgColor(colors[i]);
style.setMargin(1, 1, 1, 1);
style.setPadding(0, 0, 0, 0);
style.setBorder(Border.createBevelRaised(0xdddddd, 0xAAAAAA, 0x111111,0x020202));
button.setUnselectedStyle(style);

But if we take the theme style we wont be able to change the color.