Search code examples
blackberrymargins

Reduce space between 2 buttons in HorizontalFieldManager in BlackBerry


In Blackberry I have created a horizontal field manager and added some buttons of small size to it to display toolbar at the bottom of the screen. But my problem is there is too much space between the 2 buttons.

I have to reduce this space between 2 buttons so that I can manage to place at least 6 buttons at the bottom of the screen. I am using the BFmsg.setMargin(305,0,0,40) statement.

Following is my code :

BFcontacts = new ButtonField("Cnt")
    { 
      protected void paint(Graphics graphics) 
         {
        //Bitmap contactsbitmap = Bitmap.getBitmapResource("contacts.jpg");
             //graphics.drawBitmap(0, 0, contactsbitmap.getWidth(), contactsbitmap.getHeight(), contactsbitmap, 0, 0);
             graphics.setColor(Color.WHITE);
             graphics.drawText("Cnt",0,0);
         }
    };


    BFcontacts.setMargin(305,0,0,10);//vertical pos,0,0,horizontal pos
    HFM.add(BFcontacts);

    BFmsg = new ButtonField("Msgs")
    { 
      protected void paint(Graphics graphics) 
         {
        //Bitmap msgsbitmap = Bitmap.getBitmapResource("messages.jpg");
             //graphics.drawBitmap(0, 0, msgsbitmap.getWidth(), msgsbitmap.getHeight(), msgsbitmap, 0, 0);
             graphics.setColor(Color.WHITE);
             graphics.drawText("Msgs",0,0);
         }
    };


    BFmsg.setMargin(305,0,0,40);//vertical pos,0,0,horizontal pos : original
    HFM.add(BFmsg);

   add(HFM)

Solution

  • have u tried using custom manager u can place the contents as per ur choice like this

    Create object of this class and add items to it

    class BottomManager extends Manager
         {
             BottomManager()
             {
                 super(Manager.NO_VERTICAL_SCROLL);
             }
             protected void sublayout(int width, int height) 
             {
                 Field field = getField(0);
                 layoutChild(field,Display.getWidth(), Display.getHeight());
                 setPositionChild(field,0,0);
    
                 field = getField(1);
                 layoutChild(field,Display.getWidth(), Display.getHeight());
                 setPositionChild(field,10+getField(0).getWidth(),0);
    
                 field = getField(2);
                 layoutChild(field,Display.getWidth(), Display.getHeight());
                 setPositionChild(field,10+getField(1).getWidth(),0);
    
                 field = getField(3);
                 layoutChild(field,Display.getWidth(), Display.getHeight());
                 setPositionChild(field,getField(2).getWidth()+10,0);
    
                 setExtent(Display.getWidth(), 40);
             }
         }