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
Posts: 374
Registered: ‎02-12-2011
My Device: Bold 9780
My Carrier: Wind Mobile

ButtonField.getPreferredHeight() yields misleading results..

[ Edited ]

I have a row of ButtonFields, I am trying to get the actual height of them. For whatever reason getPreferredHeight() ONLY returns the height of the text inside and neglects all padding around.

 

This is problematic because I use the height to adjust the remaining layout before. Is there a way to get the default padding on the fly? I tried ButtonField.getPaddingTop and .Bottom however it resulted in 0. I know its only including the font height because I am actually setting the font height to X pixels, and this is what it returns yet the button surrounds the text.

Developer
Posts: 374
Registered: ‎02-12-2011
My Device: Bold 9780
My Carrier: Wind Mobile

Re: ButtonField.getPreferredHeight() yields misleading results..

I also realize the height and width are not determined completely until it is layed out in its manager. So how can I work around this and still rearrange everything else below after the height has been determine.
Trusted Contributor
Posts: 184
Registered: ‎11-26-2010
My Device: Not Specified

Re: ButtonField.getPreferredHeight() yields misleading results..

I suggest you to create a variable in the customclass, say BUTTON_HEIGHT, BUTTON_WIDTH and use them. I am not sure if I understood your question correctly, but I gave my shot.

 

A Y.

Developer
Posts: 16,997
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: ButtonField.getPreferredHeight() yields misleading results..

buttonfield is indeed tricky, it is, as far as i know, the only field that does not adhere to the contract of the preferred height.

i use a workaround and retrieve the preferred height AND the padding(?). not sure what value exactly, sorry, cannot find the code right now, something along the lines of padding, border etc.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 179
Registered: ‎06-15-2011
My Device: Storm 9550
My Carrier: Vodaphone

Re: ButtonField.getPreferredHeight() yields misleading results..

I think you can use getHeight(). It will only work if the button is already drawn.
Highlighted
Developer
Posts: 16,997
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: ButtonField.getPreferredHeight() yields misleading results..

if you want to use a button in a custom layout you can give it unlimited height in setLayoutChild, it will use only the necessary height.
after that you can use getHeight to retrieve its height.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter