Search code examples
blackberry

Aligning buttons on a screen


I would like to layout two buttons side by side and have multiple rows of these buttons like so -

B1 B2
B1 B2
B1 B2

For this do I need to combine VerticalFieldManager and HorizontalFieldManager somehow ?

Thanks


Solution

  • Here is a TableLayoutManager class to support such type of layouts. TableLayoutManager.java You can download and copy it in your porject and use it. Use TableLayoutManager like this.

    TableLayoutManager btnManager= new TableLayoutManager(new int[ {TableLayoutManager.USE_PREFERRED_SIZE, TableLayoutManager.USE_PREFERRED_SIZE},Manager.FIELD_HCENTER);
    btnManager.add(B1);
    btnManager.add(B2);
    btnManager.add(B1);
    btnManager.add(B2);
    

    you can even define your number of columns and there layout styles.