Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
clavemartin
Posts: 60
Registered: ‎08-20-2009
My Device: Not Specified
Accepted Solution

Custom space for ButtonFields:

I am new-bie, wanna provide space for two buttons. For ex: I have two buttons such as A and B. I code such a way that 'FieldListener' and add(xxx)' does that thing.

If i want to provide space between button A and B, how to do that? May be, button A can be on top and button B can be on bottom of the screen.

 

Clave.

Please use plain text.
Developer
bikas
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: Custom space for ButtonFields:

You can use setMargin() for this purpose.

Try something like this:

 

ButtonField topButton = new ButtonField( "Top Button"); int topEmptySpace = ( Display.getHeight() - topButton.getPreferredHeight() - 10 /*10 for safe margin*/) ; ButtonField bottomButton = new ButtonField( "Bottom Button"); bottomButton .setMargin(topEmptySpace, 0, 0, 0); this.add(topButton); this.add(bottomButton);

 

Regards

Bikas

Please use plain text.
Developer
Rajat_10Sep
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: Custom space for ButtonFields:

Hi,

 

As bikas suggested setMargin() is a better way of doing ,there one otherwork around also have a look at this thread

 

http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=28663&query.id=20...

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Please use plain text.
Developer
clavemartin
Posts: 60
Registered: ‎08-20-2009
My Device: Not Specified

Re: Custom space for ButtonFields:

thanks all. I'll try.
Please use plain text.
Developer
clavemartin
Posts: 60
Registered: ‎08-20-2009
My Device: Not Specified

Re: Custom space for ButtonFields:

Hi,

 

When i run this sample piece of code, it reports 'cannot find symbol 'Display'  from 'Display.getHeight()'?

 

thanks.

 

clave.

 

 

Please use plain text.
Developer
clavemartin
Posts: 60
Registered: ‎08-20-2009
My Device: Not Specified

Re: Custom space for ButtonFields:

Ok. I added import as 'import net.rim.device.api.system.Display;' and no compilation error found.

But button is not showing up in the bottom space. I have total four buttons, Btn1, Btn2, Btn3 and 'Home' button. I want 'Home' button to be placed bottm, other buttons can be upper portion one by one. 

I tried the same sample piece of code but 'Home' button is not showing in the bottom instead it shows normally down after the third button.

 

Could somone review it?

       

       ButtonField homeBtn= new ButtonField("Home", ButtonField.CONSUME_CLICK);

 

        int topEmptySpace = ( Display.getHeight() -  Btn1.getPreferredHeight() - 10 /*10 for safe margin*/) ;
        homeBtn.setMargin(topEmptySpace, 0, 0, 0);
        homeBtn.setChangeListener(listner);

        add(homeBtn); 

 

clave.

Please use plain text.
Developer
bikas
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: Custom space for ButtonFields:

Try like this:

 

ButtonField btn1 = new ButtonField("Btn1"); ButtonField btn2 = new ButtonField("Btn2"); ButtonField btn3 = new ButtonField("Btn3"); HorizontalFieldManager hfmTop = new HorizontalFieldManager(); hfmTop.add(btn1); hfmTop.add(btn2); hfmTop.add(btn3); ButtonField btnHome = new ButtonField("Home"); HorizontalFieldManager hfmHome = new HorizontalFieldManager(); hfmHome.add(btnHome); int topEmptySpace = ( Display.getHeight() - (hfmTop.getPreferredHeight() + btnHome.getPreferredHeight() + 10) ) ; hfmHome.setMargin(topEmptySpace, 0, 0, 0); this.add(hfmTop); this.add(hfmHome);

 

Regards

Bikas

 

Please use plain text.
Developer
clavemartin
Posts: 60
Registered: ‎08-20-2009
My Device: Not Specified

Re: Custom space for ButtonFields:

Appreciate your help Mr.Bikas.
Please use plain text.