Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Developer
CBissonnette
Posts: 48
Registered: 10-09-2009
My Carrier: Bell
Accepted Solution

CheckboxField on the same line with OS6

Hi,

I am testing my apps for compatibility with OS6.  I found out that if I have more then one controls on the same line, the behaviour has changed from OS5.  The first control is display while the others controls are moved outside the screen.  Any Idea on how to fix this while keeping compatibility?  Here is the code I am refering to:  

 

HorizontalFieldManager hfmOperator = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH);

int intRightSpace = Display.getWidth()/10;

LabelField lblOperator = new LabelField("");
lblOperator.setFont(Font.getDefault().derive(Font.PLAIN, 18));
lblOperator.setPadding(0, intRightSpace, 0, 0);
hfmOperator.add(lblOperator);
	  
chkADD = new CheckboxField("+",  Param.boolActiveADD);
chkADD.setFont(Font.getDefault().derive(Font.PLAIN, 24));
chkADD.setPadding(0, intRightSpace, 0, 0);
hfmOperator.add(chkADD);

chkSUB = new CheckboxField("-",  Param.boolActiveSUB);
chkSUB.setFont(Font.getDefault().derive(Font.PLAIN, 24));
chkSUB.setPadding(0, intRightSpace, 0, 0);
hfmOperator.add(chkSUB);

chkMUL = new CheckboxField("*",  Param.boolActiveMUL);
chkMUL.setFont(Font.getDefault().derive(Font.PLAIN, 24));
chkMUL.setPadding(0, intRightSpace, 0, 0);
hfmOperator.add(chkMUL);

chkDIV = new CheckboxField("/",  Param.boolActiveDIV);
chkDIV.setFont(Font.getDefault().derive(Font.PLAIN, 24));
chkDIV.setPadding(0, intRightSpace, 0, 0);
hfmOperator.add(chkDIV);

add(hfmOperator);

 

Please use plain text.
Developer
marcn
Posts: 53
Registered: 01-08-2009

Re: CheckboxField on the same line with OS6

I've noticed this too -- on the 9800 simulator running 6.0.0.141.  Is this a bug in the OS that will be fixed, or are we going to have to find some workaround for it?

Please use plain text.
Developer
marcn
Posts: 53
Registered: 01-08-2009

Re: CheckboxField on the same line with OS6

You may want to file a bug in the Issue Tracker: https://www.blackberry.com/jira/secure/Dashboard.jspa so that it gets looked at by RIM.

Please use plain text.
Developer
CBissonnette
Posts: 48
Registered: 10-09-2009
My Carrier: Bell

Re: CheckboxField on the same line with OS6

I just open a problem for this.  I might try to patch with a manager in a manager?  Don't know if it's going to work but if any of you got an idea, please share it with me.  Thanks.

Please use plain text.
Developer
dnepr
Posts: 723
Registered: 03-12-2009

Re: CheckboxField on the same line with OS6

I can confirm this bug as well.

 

I think a workaround would involve manually setting positions for your fields within the manager.

Please use plain text.
Developer
marcn
Posts: 53
Registered: 01-08-2009

Re: CheckboxField on the same line with OS6

The only workaround that I've been able to come up with so far is to override the layout method in the CheckboxField and pass a fixed width to the super method:

 

protected void layout(int width, int height) {
	super.layout(100, height);
}

 

The problem with this approach is that the width of the content can vary from device to device depending on the default font size, etc. and it may not be feasible to try and force a specific width.

Please use plain text.
Developer
dnepr
Posts: 723
Registered: 03-12-2009

Re: CheckboxField on the same line with OS6

You can get this to be more "precise" by measuring the length in pixels of checkbox label and add an imaginary number to offset the actual box.

Please use plain text.
Developer
CBissonnette
Posts: 48
Registered: 10-09-2009
My Carrier: Bell

Re: CheckboxField on the same line with OS6

As a workaround I did include the lines provided by marcn.  It worked fine.  My code now looks like this:

 

 

HorizontalFieldManager hfmOperator = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH);
       
        
        final int intRightSpace = Display.getWidth()/9;
        
        LabelField lblOperator = new LabelField("") {
            protected void layout(int width, int height) {
                super.layout(intRightSpace, height);
                }
            };
        lblOperator.setFont(Font.getDefault().derive(Font.PLAIN, 18));
        lblOperator.setPadding(0, intRightSpace, 0, 0);
        hfmOperator.add(lblOperator);
              
        chkADD = new CheckboxField("+",  Param.boolActiveADD) {
            protected void layout(int width, int height) {
                super.layout(intRightSpace, height);
                }
            };
        chkADD.setFont(Font.getDefault().derive(Font.PLAIN, 24));
        chkADD.setPadding(0, intRightSpace, 0, 0);
        hfmOperator.add(chkADD);
       
        chkSUB = new CheckboxField("-",  Param.boolActiveSUB) {
            protected void layout(int width, int height) {
                super.layout(intRightSpace, height);
                }
            };
        chkSUB.setFont(Font.getDefault().derive(Font.PLAIN, 24));
        chkSUB.setPadding(0, intRightSpace, 0, 0);
        hfmOperator.add(chkSUB);

        chkMUL = new CheckboxField("*",  Param.boolActiveMUL) {
            protected void layout(int width, int height) {
                super.layout(intRightSpace, height);
                }
            };
        chkMUL.setFont(Font.getDefault().derive(Font.PLAIN, 24));
        chkMUL.setPadding(0, intRightSpace, 0, 0);
        hfmOperator.add(chkMUL);

        chkDIV = new CheckboxField("/",  Param.boolActiveDIV) {
            protected void layout(int width, int height) {
                super.layout(intRightSpace, height);
                }
            };
        chkDIV.setFont(Font.getDefault().derive(Font.PLAIN, 24));
        chkDIV.setPadding(0, intRightSpace, 0, 0);
        hfmOperator.add(chkDIV);

        add(hfmOperator);

 

Thanks all for your help. 

 

 

Please use plain text.
Developer
marcn
Posts: 53
Registered: 01-08-2009

Re: CheckboxField on the same line with OS6

 


CBissonnette wrote:

I just open a problem for this.  I might try to patch with a manager in a manager?  Don't know if it's going to work but if any of you got an idea, please share it with me.  Thanks.


 

Can you post a link to the issue that you logged?  I'd like to add a vote on it (as should anyone else encountering this issue).

 

Please use plain text.
Developer
marcn
Posts: 53
Registered: 01-08-2009

Re: CheckboxField on the same line with OS6

[ Edited ]

After a bit more work, I've come up with a workaround that doesn't require the use of a fixed width.  Instead, it measures the width of the text using the getAdvance() method of the Font class, and adds some extra width to account for the width of the checkbox and padding (19 pixels).

 

The updated workaround is as follows.  Note that I'm specifically testing for the 9800 Torch model, since that's the only device simulator released with 6.0 so far - until I know if this is a device-specific bug or a 6.0-wide bug I just check for the specific device model:

 

protected void layout(int width, int height) {
    if (DeviceInfo.getDeviceName().startsWith("9800")) {
        width = Font.getDefault().getAdvance(getLabel()) + 19;
    }
    super.layout(width, height);
}
Please use plain text.