Wednesday, February 3, 2010

A Simple Table Component for Blackberry

Just worked on making a J2ME based prototype for a Blackberry (JDE 4.7+). The documentation, the website and the API are horrible, to say the least. We are using the Eclipse Plugin for development. One of the prime difficulties we faced was the absence of a well-defined table component. "ListField" is horribly designed and the example that is given in their documentation does needs serious improvement. Moreover, to make a flexible component that renders a list of messages (like the SMS message list) with each composite row selectable as a whole, no example could really help. So, I have made two components that you can improve upon and use as you please.

The first one, that is given in this post, is a simple table. It takes a 2-D array of fields and converts it into a visual table. It simply improves upon ListField. You would need the following three classes:

BSimpleTable.java
BSimpleTableCallback.java
BSimpleRowRenderer.java

Then in you code, use a similar code snippet to make and add a table (here we use it to create the title of the screen):

Field[][] titleContent = new Field[1][];
titleContent[0] = new Field[3];
titleContent[0][0] = new LabelField("S.No.",
DrawStyle.ELLIPSIS);
titleContent[0][1] = new LabelField("Message",
DrawStyle.ELLIPSIS);
titleContent[0][2] = new LabelField("Time",
DrawStyle.ELLIPSIS);
int[] widthPercent = {10,63,27};
int[] paddings = { 5, 0, 0 };
setTitle(new BSimpleTable(titleContent,
widthPercent, paddings,
Field.NON_FOCUSABLE));

If you don't want to sign the application, hard code the total screen width instead of using Display.getWidth()

Also, see: Version Specific Developmnet Guides (3.6 to 5.0 beta)

2 comments:

Ari Fikri said...

I could never able to set the field alignment to right align.
Can you help me ?

Ari Fikri said...

I could never able to set the field to right align.
Can you help me ?