08-06-2010 07:48 AM
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);
Solved! Go to Solution.
08-06-2010 12:54 PM
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?
08-06-2010 12:58 PM
You may want to file a bug in the Issue Tracker: https://www.blackberry.com/jira/secure/Dashboard.j
08-06-2010 01:42 PM
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.
08-06-2010 01:48 PM
I can confirm this bug as well.
I think a workaround would involve manually setting positions for your fields within the manager.
08-06-2010 01:54 PM
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.
08-06-2010 02:58 PM
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.
08-07-2010 07:48 AM
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.
08-09-2010 12:29 PM
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).
08-10-2010 02:08 PM - last edited on 08-10-2010 02:11 PM
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);
}