Create a grid layout
You can change the grid after you create it. For example, you can add fields, delete fields, or change the grid's properties.
Code sample: Creating a grid layout
/*
* GridFieldManagerDemo.java
*
* Research In Motion Limited proprietary and confidential
* Copyright Research In Motion Limited, 2009
*/
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
public class GridFieldManagerDemo extends UiApplication
{
public static void main(String[] args)
{
GridFieldManagerDemo theApp = new GridFieldManagerDemo();
theApp.enterEventDispatcher();
}
GridFieldManagerDemo()
{
pushScreen(new GridScreen());
}
}
class GridScreen extends MainScreen
{
public GridScreen()
{
setTitle("GridFieldManager Demo");
GridFieldManager grid = new GridFieldManager(2,3,0);
grid.add(new LabelField("one"));
grid.add(new LabelField("two"));
grid.add(new LabelField("three"));
grid.add(new LabelField("four"));
grid.add(new LabelField("five"));
grid.setColumnPadding(20);
grid.setRowPadding(20);
add(grid);
// The grid looks like this:
// | one | two | three
// | four | five |
// insert a cell first row, second column
grid.insert(new LabelField("insert"), 0, 1);
// The grid now looks like this:
// | one | insert | two
// | three | four | five
// delete a cell second row, second column
grid.delete(1,1);
// The grid now looks like this:
// | one | insert | two
// | three | | five
// Add field to first unoccupied cell
grid.add(new LabelField("new"));
// The grid now looks like this:
// | one | insert | two
// | three | new | five
}
}
Previous topic: Creating a grid layout