Working with 3rd party Layout Manager in BlackBerry

As you already learned in my previous article the BlackBerry User interface API follows a Fields/Layout Managers/Screens models: Fields are contained within layout managers, which arrange and draw them in specific positions. We have some built in layout managers:

We have four built in layout managers:

  1. VerticalFieldManager
  2. HorizontalFieldManager
  3. FlowFieldManager
  4. DialogFieldManager

Here we will discuss about one another layout managers this comes under Java user interfaces and provided from the third party to use it in swing on the java platform, we call it 3rd party layout managers. Here we have one 3rd party layout managers for BlackBerry that is:

3rd party layout managers

  • GridFieldManager : This layout manager provides an easy way to manage a table or list layout on the screen, it is pretty easy to use and works as one would expect. It will let the user specify a number of grid columns when it's instantiated. The number of rows will vary depending on the number of fields added.

The table below explores the properties which are used with GridFieldManager:

FIXED_SIZEIn this property width or height is a fixed size in pixels.
PREFERRED_SIZEIn this property width or height is a preferred size based on the maximum preferred size of the fields.
In this property width or height is a preferred size up to a maximum size.
AUTO_SIZEIn this property width or height is based on available screen space.

Let's see an example of GridFieldManager

Step 1 : Create an BlackBerry Project in BlackBerry Java Plug-in/Eclipse.

Step 2 : Open the class and code inside the class for GridFieldManager :

my package in blackberry

First you have to import these two classes:

import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;

Here is the complete class:

public final class MyScreen extends MainScreen

    public MyScreen()

int row = 5;

      GridFieldManager  dfm = new GridFieldManager(row,2, 0);
// Row 1
      dfm.add(new LabelField("Label 1")); 
new LabelField("Label 2")); 
// Row 2 
      dfm.add(new LabelField("Label 3")); 
new LabelField("Label 4")); 
// Row 3 
      dfm.add(new LabelField("Label 5")); 
new LabelField("Label 6"));
// Row 4 
      dfm.add(new LabelField("Label 7")); 
new LabelField("Label 8"));
// Row 5
      dfm.add(new LabelField("Label 9")); 
new LabelField("Label 10"));                    



GridFieldManager in blackberry

Now as I said, GridFieldManager is working with grid columns and rows. So, see what happen if we change the number of columns in grid. In below picture you see we change the column numbers 2 to 3 and the effect you will see in below screenshot:



blackberry GridFieldManager

Thank You......