Issues with ObjectList​Field



I have a simple ObjectFieldList where i add string values using a for loop. The trouble is that the list items are shown right-aligned by default. I would like to have them left-aligned. Can someone tell me how this can be done?

Also in some cases the length of the string which is added to the list is pretty long and thus i would like to have the string displayed in multiple lines. I tried setrowheight() but its not working. Can someone help here too?



simon_hain2010-01-08 07:11

you control the painting yourself on drawListRow, modify the code there to paint it different.

setRowHeight changes the height of all rows, again you can modify the y parameter in a drawText method to paint the text on another line.

Sakberry2010-01-11 02:02

Thanks for your reply!

I am using the drawListRow() method of the ObjectListField instance to print the string on a lower line.

The drawListRow method has the following paramerters:

ListFIeld - The list to be repainted

Graphics - Graphics context for this field - ?

index - Row index

int y - Distance from top where string should be inserted

int width - width of row

From the above parameters, i am not sure what needs to be given for the Graphics instance. I tried creating an instance of the Graphics class but it asks for a BitmapField instance as a parameter.

So i need some guidance with just this parameter "Graphics g". Any help will be appreciated.

Btw anyone have a working example for reference? If yes then kindly let me know.



simon_hain2010-01-11 03:15

you don't have to initialize a new graphics object, you get one as a parameter.

you can use this to paint the text, using graphics.drawText.

here is a simple example:

graphics.drawText(myObject.getText(), 5, y, DrawStyle.ELLIPSIS);

Sakberry2010-01-11 07:48

Thanks for all your help so far....

In the drawListRow() method of ObjectListField, i am using the setRowHeight and drawText() methods respectively. Please refer the below code for more details.....

public void drawListRow(ListField list,Graphics g,int index,int y,int width)
        catch(Exception ex)

Here for the drawText method i need the "i"th item of my list to be displayed. Unfortunately, the listfield which is one of the parameters of drawlistRow() method does not seem to have any method like get() in ObjectListField that returns the current item.

Can you suggest a solution to this?

THanks for your help!


simon_hain2010-01-11 07:52

do not use setRowHeight. it is a setting for the whole listfield, if you call it in the draw method you have an endless loop in the worst case.

you can use  the get method of the callback to retrieve an item.

sachin_r2010-01-11 09:07

Take one vector in callback...

And when you add string in the list add that in the vector too.

and call the string at the position from vector in drawList e.g

addItem(String str){






if(index < vec.size()){




peter_strange2010-01-11 10:56

I'm with Simon and not sachin_r on this - in your drawListRow, use the get you have coded as part of the ListFieldCallback rather than obtaining the data from the Vector directly.  I've got myself in trouble when I used two different ways to get the same data.

sachin_r2010-01-12 00:44

I just gave an idea for initial testing

getText() is good practice.

But to call getText() the object should stored in some container....

When we drawText list has to know which text to draw... to draw text the Item stored at the particular index should be retrived and then used.

In my applications, i used set and get methods but the objects are stored in vector.

simon_hain2010-01-12 04:57

no clue what you are talking about, sachin_r.