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
Highlighted
Contributor
Posts: 16
Registered: ‎08-15-2011
My Device: 9780
My Carrier: Movistar

CheckboxField Alignment

Hey everyone!

 

After trying to align a checkbox to the right and not being able to do so, I got  a simple solution by extending the CheckboxField class. I've been reading a lot and it seems it's causing trouble to a lot of people, so here's my code:

 

import net.rim.device.api.ui.component.CheckboxField;

public class CustomCheckbox extends CheckboxField{
	
	public CustomCheckbox(){
		super();
	}
        public CustomCheckbox(String label, boolean checked){
        	super(label, checked);
        }
        public CustomCheckbox(String label, boolean checked, long style){
    	        super(label, checked, style);
        }
    
        protected void layout(int width, int height) { super.layout(getPreferredWidth(), getPreferredHeight()); }
}

The bold part did the trick for me.

 

Now to add a checkbox and align it the way you want, just instantiate it and as style you can set the alignment you want.

 

CustomCheckbox cbShow = new CustomCheckbox("", true, CustomCheckbox.FIELD_RIGHT);
mainManager.add(cbShow);

I really hope this may help somebody.

 

Thanks and sorry for my english, my first language is spanish.