January 27, 2021
Hot Topics:

Introducing a Lightweight UI Toolkit: Shake Your User Interface

  • By Ibon Urrutia
  • Send Email »
  • More Articles »

It is very important that you set the containing form as non-scrollable: List implements its own scroll and your application will behave strangely if you don't do so.

In your application, you pass a Vector of YWRecords to the List, but how is it going to be rendered a YWRecord? They aren't LWUIT components, so you have to tell to the List how to show them. You defined a LocationRenderer class that implements ListInterface:

class LocationRenderer extends Label implements ListCellRenderer {

   public LocationRenderer() {

   public Component getListCellRendererComponent(List list,
      Object value, int index, boolean isSelected)
      final YWRecord record = (YWRecord) value;
      if (isSelected) {
      } else {

      return this;

      public Component getListFocusComponent(List arg0) {
         return this;


ListCellRenderer defines only two methods:

  • getListCellRendererComponent: Receives all values passed to the List, and returns a LWUIT component that displays information as you want. And when you say "component," you are also referring to Containers, so you can see that a List can be composed of complex components.
  • getListFocusComponent: Returns a component that is going to be used to paint the pointer or the current focused component. You can think of it as it was a magnifying glass that you move up or down above the List: It must have some degree of transparency to see what is under it when the focus on the List moves. Once the focused item reaches the cell location, this Component is drawn under the selected item. It can be null, but defining it in your List in conjunction with setting smooth scrolling brings you a cool effect.

In LwuitWeather, you have implemented a common paradigm on LWUIT: You create a component that also implements the ListCellRenderer interface, so it can be returned from those methods. This way, you avoid creating a new Component each time getListCellRendererComponent is called. Remember that we are developing to devices with big memory constraints.

Notice that getListCellRendererComponent also receives all the List as a parameter: With a little coding, it will be easy to create a List that focuses elements and alters the appearance of near components, like in a Fish Eye Menu. I will let that be an exercise for readers to implement it.

Finally, you should react to selections of items on that list. To achieve that, PlacesDisplay will be your actionListener, whose action performing method is shown next:

public void actionPerformed(ActionEvent evt) {
   List selectionList = (List) evt.getSource();
   YWRecord newSelected = (YWRecord)

   // We identify when finishes our browsing when we have got
   // a complete Yahoo code
   if (Character.isDigit(newSelected.yahooCode.
       charAt(newSelected.yahooCode.length() - 1))) {
   } else {
       createLocationForm(yahooHome + newSelected.url);

Figure 4: Location List

Page 3 of 7

This article was originally published on September 25, 2008

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date