BlackBerry Grid Layout Manager updated

I made some small tweaks to the GridFieldManager – a couple of new constructors that allow you to specify (in pixels) the widths of the individual columns, and the height for the rows (so that all rows have the same height instead of them being dynamically calculated).

As usual, the latest version is available here

This makes it for example easy to do a nice looking set of right-aligned labels and fields:

view plaincopy to clipboardprint?
  1. setTitle(“Login”);
  2. Manager gridFieldManager = new GridFieldManager(new int[] {100160}, 300);
  3. // Row 1
  4. gridFieldManager.add(new LabelField(“Username:”, Field.FIELD_RIGHT | Field.FIELD_VCENTER));
  5. gridFieldManager.add(new BasicEditField(“”“Jimbo”200, Field.FIELD_LEFT | Field.FIELD_VCENTER));
  6. // Row 2
  7. gridFieldManager.add(new LabelField(“Password:”, Field.FIELD_RIGHT | Field.FIELD_VCENTER));
  8. gridFieldManager.add(new PasswordEditField(“”“password123”200, Field.FIELD_LEFT | Field.FIELD_VCENTER));
  9. add(gridFieldManager);
  10. add(new ButtonField(“Login”, Field.FIELD_HCENTER));

Gives this:


Of course you probably want to specify the 2nd column relative to the screen width and the first column (e.g. Display.getWidth()-100, instead of just 160).

Leave a Reply

Your email address will not be published. Required fields are marked *