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
krishnanmurari
Posts: 80
Registered: ‎06-06-2011
My Device: bold 9000
My Carrier: airtel
Accepted Solution

Label field with check box error in layout.

Hi all,

 

I have a big problem with label fields and checkbox.

 

I have a huge text which goes more than 5 to 6 lines. So i have created a horizontal field manager and added a checkbox field and the text is created as a rich text field and i have add it to the horizontal field manager.

 

on the simulator it works fine but when i put on a device of os 6.0 then the allignmet of the fields are totally changed that is text is occupying only half of the screen and the check box with no text is occupying half the screen.

 

my code is like this.

 

Horizontalfieldmanager HFM =  new Horizontalfieldmanager ();

checkboxfield checkboxfield1 = new checkboxfield ("",true);

RichTextField text = new RichTextField("this is the text that i was talking which is more than one to 5 or 6 lines fsdkjhgshfgshjfgksdgfsgdfg");

 

HFM.add(checkboxfield1);

HFM.add(text);

HFM.setmargin(10,10,10,10);

this.add(HFM);

 

The above is a sample code but im following this exactly.

 

 

 samplecheckbox&labelfield.png

 

Has anyone faced this problem before if so please do let me know if you have found a solution.

 

Any ideas are also welcomed.

 

 

 

 

Thanks in advance.

Krishnan

Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,556
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Label field with check box error in layout.

[ Edited ]

Hello Krishnan,

 

By default, the CheckBoxField will use all available width when laying out its components, depending on the OS/Bundle version of the simulator vs. the device, 'available width' may be interpretted differently.

 

If full available width is not desired, then CheckboxField.NO_USE_ALL_WIDTH style must be specified using the appropriate constructor.

Source

 

EDIT: Fixed source link (a few special characters were present it seems.)

 

The simplest approach then would be to try constructing your CheckBoxField with the noted style. If this does not provide the desired results, you may need to override the layout of your fields to set specific dimensions.

 

Please let me know if you have additional questions.

 

Erik Oros

BlackBerry Development Advisor


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Label field with check box error in layout.

Thanks Erik. 

 

Is there a work around  for those of us working on OS's before OS 7.0?

 

BTW: Link does't seem to work. 

Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,556
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Label field with check box error in layout.

[ Edited ]

Hi Peter,

 

Apologies for the link. The NO_USE_ALL_WIDTH was originally referenced in the 6.0 API Documentation which led me to believe it was available in earlier versions. Of course, clicking that link in the 6.0 documentation doesn't lead anywhere. According to the 7.0 API Reference, CheckBoxField.NO_USE_ALL_WIDTH is available only as of 7.0 as you noted.

 

I haven't played around with this too much myself, but perhaps having:

- One HorizontalFieldManager containing...

- Two VerticalFieldManagers. The first of fixed-width (to hold the CheckBoxField) and the second that occupies the remaining space.

 

This way, the CheckBoxField would (hopefully) size to its VFM, while the RichTextField would occupy the second VFM. Again, I haven't tested this out directly to see how the CheckBoxField behaves under these circumstances, but will dig into this a little more and let you know what I find.

 

EDIT: Peculiarly in 5.0, the CheckBoxField appears to require USE_ALL_WIDTH in order to use all available space (by default it does not); the opposite of 7.0.

 

Erik Oros

BlackBerry Development Advisor


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Label field with check box error in layout.

I would suggest something even simpler - limiting the width of the CheckboxField itself by overriding its layout with something like:

protected void layout(int w, int h) {
  super.layout(Math.min(w, myDesiredWidth), h);
}

 If I knew how to find out the size of the box itself, I'd suggest something more generic...

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,556
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Label field with check box error in layout.

After a few tests, we have the following:

 

(1) On 5.0, it appears that simply adding the CheckboxField and RichTextField to a HorizontalFieldManager does suffice as the default behaviour is not to use all width.

 

(2) On 6.0 and above, CheckboxField appear to have changed to use all available width instead by default. As recommended by arkadyz above, overriding the layout method of the CheckboxField to set a desired width of the field directly does yield the desired results. This is more straight-to-the-point than the approach I initially noted with multiple managers.

 

(3) In 7.0 and above, it should also be possible to use the CheckboxField.NO_USE_ALL_WIDTH flag to produce behaviour as in (1).

 

Erik Oros

BlackBerry Development Advisor


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Label field with check box error in layout.

So the only issue left is how do you know how big the Checkbox needs to be in OS 6.0?  Presumably this is Font size dependent and in addition, will want to be larger on touch screen devices too.  So not a trivial decision I suspect. 

Please use plain text.
BlackBerry Development Advisor
oros
Posts: 1,556
Registered: ‎04-12-2010
My Device: BlackBerry Z10
My Carrier: Bell

Re: Label field with check box error in layout.

Correct. Unfortunately there aren't any direct APIs to get the width of the box.

 

Calling CheckboxField.getFont().getAdvance(char c) comes close but is unreliable as, for instance, passing in 'W' for c will be too wide on the largest font and not wide enough on the smallest font. Basically, there doesn't appear to be 1:1 scaling in font width and the width of the box.

 

This will likely come down to picking a safe value that should accomodate most scenarios.

 

Erik Oros

BlackBerry Development Advisor


Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.
Please use plain text.
sdw
Contributor
sdw
Posts: 29
Registered: ‎05-30-2011
My Device: Developer
My Carrier: N/A

Re: Label field with check box error in layout.

It might be undocumented and potentially fragile, but I found the following to give me acceptable results in OS5, OS6 and OS7 in an application compiled for OS5 (at least in the simulators):

 

First, go here and grab the constant value of NO_USE_ALL_WIDTH as defined in OS7 SDK (2147483648L).

 

Then, I added this constant in my own code and passed it into the constructor of my CheckboxField.  For example:

 

CheckboxField mycb = new CheckboxField("Some text", false, MY_NO_USE_ALL_WIDTH);

 

Please use plain text.