I need to align a CheckboxField to the right of a fixed text (on Blackberry) like the "manage connections" dialog. The code is:
final HorizontalFieldManager hfm = new HorizontalFieldManager(USE_ALL_WIDTH);
hfm.add(new LabelField("Test me please", LabelField.ELLIPSIS | FIELD_LEFT | FIELD_VCENTER | USE_ALL_WIDTH));
cbx = new CheckboxField(null, false, FIELD_RIGHT | CheckboxField.NO_USE_ALL_WIDTH);
hfm.add(cbx);
I tried various combinations of "USE_ALL_WIDTH", "NO_USE_ALL_WIDTH" and similar flags, but I still can't get what I want: text all the way to the left, and check box all the way to the right. If the label is set to USE_ALL_WIDTH, the checkbox disappears, and if it's not set, the check开发者_如何学编程box is displayed near the text (not on the right side of the hfm).
Use following code,this will solve your problem.
HorizontalFieldManager hfm = new HorizontalFieldManager(Field.USE_ALL_HEIGHT);
LabelField lblShow = new LabelField("Test me please ", Field.FIELD_LEFT);
CheckboxField cbShow = new CheckboxField("", false, CheckboxField.FIELD_RIGHT );
VerticalFieldManager vfmLeft = new VerticalFieldManager();
VerticalFieldManager vfmRight = new VerticalFieldManager(Field.USE_ALL_WIDTH);
vfmLeft.add(lblShow);
vfmRight.add(cbShow);
hfm.add(vfmLeft);
hfm.add(vfmRight);
add(hfm);
Use This style bit to align checkbox to right.
private static final long checkBoxStyle = 134217728;
add(new CheckboxField("test " , false, checkBoxStyle | USE_ALL_WIDTH));
精彩评论