Skip Headers
Lightweight UI Toolkit Developer's Guide
Release 1.5
E23376-03
  Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
 
Next
Next
 

A LWUIT Mini FAQ

This appendix addresses common questions about LWUIT.

Performance on the Java ME SDK or the Wireless Toolkit is very slow, what is the problem?

There are documented issues of slow performance due to Hyperthreading.

How does painting in LWUIT differ from Swing/AWT?

Generally both are very much alike. There are, however, some minor key differences that might “bite” an unsuspecting Swing/AWT developer:

Scrolling isn't working like I expect. What went wrong?

There are several common possibilities.

What is a painter? Why not just use an image?

The idea behind a painter is simple, provide flexibility to the developer and allow the developer to define rendering suitable for his needs on any device. While images provide decent flexibility for artists' ideas, painters provide limitless flexibility:

Is LWUIT identical across all platforms?

Yes and No.

The basic core API is the same on most tested platforms and is binary compatible, allowing MIDP applications to run on Java SE (for example, in the Resource Editor actual MIDlet code is running in Java SE).

The catch is in several details:

For more details on these issues check out the portability chapter.

Does LWUIT support 3 SoftButton devices?

Yes, 3 SoftButton mode is implemented in display. However, since there is no reliable way to detect 3 SoftButton phones this features can be activated either programmatically or through a JAD file attribute.

A device doesn't seem to work with LWUIT. What should I do?

Is it a MIDP 2.0/CLDC 1.1 device? If it is then please mail lwuit@sun.com with the following additional details:

I want my application to look "native" on the device. Is there any way to accomplish that?

While LWUIT is designed to do the exact opposite (support your own look and feel) a native look and feel can be partially achieved if you implement a theme or look and feel that resembles the native look.

This won't work very well on most devices since there is no way to detect if the user switched the default theme.

Downloadable themes are probably a good approach for a strong user community.

The UI for my touch screen phone seems too small for my fingers. How do I make the UI more appropriate for such a device?

Use a global padding setting in the theme to increase the size of all widgets to a point where they are big enough for a finger tip.

Why am I getting memory errors in LWUIT? Why is LWUIT is consuming a lot of memory in my memory monitor?

Check that your application doesn't hold onto pointers for components. Because 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. Check out the LWUIT blog for more information on the subject of tracking and identifying memory issues.

Why won't my list/text area scroll? Why does my list/text area jump around?

You need to disable the scrolling for the form using myForm.setScrollable(false) and you should place the list in the center of a border layout. For deeper understanding of why this is required, read the next question about scrolling.

How do I change the appearance of the list? Remove the numbers from the side etcetera? Can I nest containers in the list?

Listis designed for a very large number of element and fast traversal. You can use its cell renderer facility to customize it any way you want as explained here. How the list can scale and grow is explained here and additionally here.

My application freezes or stalls. How do I fix this?

99% of the problems of this type are related to Event Dispatch Thread (EDT) violations.

What is the Event Dispatch Thread (EDT)?

The EDT broadcasts all the events in LWUIT. It is also responsible for drawing all elements on the screen.The EDT thread is responsible for drawing all screen elements, if it is blocked by a long running operation elements won't update and key/pointer events won't be received. 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 and callSeriallyAndWait. A different option is to use invokeAndBlock.

I'm not opening any threads, why am I having problems?

A typical application always uses at least two threads, lifecycle and the EDT. The lifecycle thread is the callback thread used for the application. For example, in MIDP the startApp method is invoked from the MIDP thread which is different from the EDT.

Does anything work from a separate thread?

There are no guarantees, but repaint() should generally work from every thread and show() should as well.

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.

How do I show Video?

Use MMAPI to create a Player object, then use the VideoComponent class.

Can I create my own components?

Everything in LWUIT is fully extensible.You can derive from any component and extend it. It is demonstrated in the Chapter 14 and it is discussed extensively in the blog at http://codename-1.blogspot.com/.

I'm trying to display an animated gif. Why isn't it working?

Animated gifs can be shown in MIDP using the MMAPI and VideoComponent (see How do I show Video?). 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.

I'm having issues on a Windows Mobile device?

Windows mobile VMs vary significantly in their quality. If the VM is giving you problems try the Phone ME open source VM port for Windows mobile devices.

How do I create resource (.res) files?

Use the Resource Editor or the Ant task.

What is the difference between the Resource Editor and the Ant task?

The difference is mainly in the use case, the ant tool is designed mostly for developer related resources (locales, application images, etcetera). The Resource Editor is targeted for use by graphic designers.