BlackBerry Forums Support Community

BlackBerry Forums Support Community (
-   Developer Forum (
-   -   Display problem overriding ButtonField (

laurre 08-29-2011 08:24 AM

Display problem overriding ButtonField

I have a problem overriding ButtonField. As the Field.USE_ALL_WIDTH flag doesn't work for ButtonField, I have to extend it.

I just override the layout method like this :

protected void layout(int width, int height) {
setExtent(width, getPreferredHeight());

I have several buttons in a VerticalFieldManager. My first button displays correctly, but others are empty (good size, but no text). I have to click the buttons to make the text appear.

Am I missing something ? The problem comes from the layout method I guess, because it's the only method I override.

Thanks !

Edit : Tested on JDE 4.7.0 and 6.0.0, same behaviour

hrbuckley 08-29-2011 10:00 AM

Re: Display problem overriding ButtonField
I'm not on a machine where I can look at my layout code at the moment, but IIRC unless the Manager does something about it, layout is called with huge numbers (infinity for practical perposes) for width and height. The text then gets centred between 0 and the huge number. Use the debugger to see what the value for width is to confirm this, but what you probably want to use is Device.getWidth().

laurre 08-29-2011 10:17 AM

Re: Display problem overriding ButtonField
I have already debugged : the value for width is 324 (the display's width is 360), and for height 1073741743, but in my case I ignore this last value, so it should be ok...

getPreferredHeight() returns 20 in my case. So the buttons should display correctly, I don't get it !

laurre 08-30-2011 07:17 AM

Re: Display problem overriding ButtonField
It seems that another thing is done in the super.layout() method. Seems to be an internal stuff, for text positioning I think.

The technique I have found, even if it is not the best one I guess :

- don't override layout
- override getPreferredHeight() and getPreferredWidth() :


public int getPreferredHeight() {
    if (isStyle(USE_ALL_HEIGHT)) {
          return Integer.MAX_VALUE;
    return super.getPreferredHeight();

public int getPreferredWidth() {
    if (isStyle(USE_ALL_WIDTH)) {
          return Integer.MAX_VALUE;
    return super.getPreferredWidth();

I hope this works in any situations. I know it is not very very clean, if you have a better idea...

All times are GMT -5. The time now is 08:23 PM.

Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.