3

I have a list on LWUIT form. I want to add background image to this form. I try using the following piece of code. The image is being set in background but the list distorts while scrolling.

    categoryList=new List(categories.categoryVector);

    categoryList.setListCellRenderer(new CategoryListCellRenderer());

    Image img=parentMIDlet.constants.getBgImage();

    //img=img.scaled(this.getPreferredW(), this.getPreferredH());
    getStyle().setBackgroundType(Style.BACKGROUND_IMAGE_ALIGNED);

    getStyle().setBackgroundAlignment(Style.BACKGROUND_IMAGE_ALIGN_CENTER);

    getStyle().setBgImage(img);

    //getStyle().setBgPainter(new ImagePainter(img));



    addComponent(BorderLayout.CENTER,categoryList);

    categoryList.isScrollableY();

    categoryList.setFixedSelection(List.FIXED_NONE);

    categoryList.addActionListener(new CategoryListActionListener(mainMIDlet,categoryList));
Chetan Khilare
  • 285
  • 1
  • 3
  • 14

1 Answers1

3

If you are using 1.5 or newer you should use:

getStyle().setBackgroundType(Style.BACKGROUND_IMAGE_ALIGNED_CENTER);

Make sure the list bg transparency is set to 0 for both selected and unselected styles. Make sure the parent form is set to scrollable false.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65