ARTICLE

Working with 3rd party Layout Manager in BlackBerry

Posted by Manish Tewatia Articles | Mobile & Embedded September 23, 2011
The GridFieldManager provides an easy way to manage a table or list layout on the screen, with the help of this article I will explain the GridFieldManager with an example.
Reader Level:

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:

PropertyDescription
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.
PREFERRED_SIZE_
WITH_MAXIMUM
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 MyScreen.java 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")); 
      dfm.add(
new LabelField("Label 2")); 
     
     
// Row 2 
      dfm.add(new LabelField("Label 3")); 
      dfm.add(
new LabelField("Label 4")); 
        
     
// Row 3 
      dfm.add(new LabelField("Label 5")); 
      dfm.add(
new LabelField("Label 6"));
     
     
// Row 4 
      dfm.add(new LabelField("Label 7")); 
      dfm.add(
new LabelField("Label 8"));
     
     
// Row 5
      dfm.add(new LabelField("Label 9")); 
      dfm.add(
new LabelField("Label 10"));                    
                            
      add(dfm);       

    }
}

Screenshot

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:

GridFieldManager

Screenshot

blackberry GridFieldManager

Thank You......

COMMENT USING

Trending up