0

I have a LWUIT form which contains a list, a number of items has been added to the list, items themselves are strings (I want to make them as statements).

returns

My simple problem is that end user cannot see the whole statements(strings). I tried the below method but the scrolling won't move.

All of form.setScrollableY(true), form.setScrollabelX(true), and form.setScrollable(true).

This is the code

import javax.microedition.midlet.*;
import com.sun.lwuit.layouts.*;
import com.sun.lwuit.*;

public class HelloLWUITMidlet3 extends MIDlet
{

  public void startApp()
  {
     com.sun.lwuit.Display.init(this);

     final com.sun.lwuit.Form form = new com.sun.lwuit.Form("");

     final com.sun.lwuit.List l = new com.sun.lwuit.List();

     l.addItem("MY favourite Science is computer Sciences");

     l.addItem("MY favourite   computer Science  subject is programming");

     l.addItem("MY favourite  programming language is java ");

     form.setScrollableY(true);

     form.setScrollableX(true);

     form.addComponent(l);

     form.show( );  
  }

  public void pauseApp()
  {

  }

  public void destroyApp(boolean unconditional)
  {

  }
}
GSerg
  • 76,472
  • 17
  • 159
  • 346
PHPFan
  • 756
  • 3
  • 12
  • 46

1 Answers1

1

First of all, scrolling horizontally back and forth to read content is really bad UX. This answer will solve only the vertical scrolling issue.

The problem with your code is that you are adding a scrollable (List) inside another scrollable (Form). This leads to unexpected results, since it is not clear which component should handle scrolling. This can be fixed by using the BorderLayout in the form and placing the list at the center.

...
form.setScrollable(false);
form.setLayout(new BorderLayout());
form.addComponent(BorderLayout.CENTER, l);

...

This will enable vertical scrolling, but the horizontal scrolling will not work.

Clarification about scrolling:

LWUIT's approach to scrolling is based on Focus, which means that a Container scrolls because the focused element is out of the screen. This has the consequence that LWUIT does not support scrolling elements bigger than the screen and, thus, that your List will not be scrollable horizontally. (Source:LWUIT mini FAQ )

Suggestion:

The maximum element height is taken as the component height in a List. This makes the List component adequate to show data that is "pre-formatted" in a specific way, like contact lists of a folder's details list. If you want to stack pieces of text of variable length, you should
use a Form with BoxLayoutY and put your text in various TextAreas.

void startApp() {
    Display.init()
    final Form form = new Form("Title");

    addItem(form, "String..");
    // as many times as you like
    addItem(form, "String..");

    form.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
    form.setScrollableY(true);
    form.show()
}


void addItem(Form f, String s) {
    TextArea t = new TextArea(s);
    t.setGrowByContent(true);
    f.addComponent(t);
}
igordsm
  • 464
  • 2
  • 8