Align checkbox to the right on Blackberry

淺唱寂寞╮ 提交于 2019-12-12 04:27:43

问题


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 checkbox is displayed near the text (not on the right side of the hfm).


回答1:


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);



回答2:


Use This style bit to align checkbox to right.

private static final long checkBoxStyle = 134217728;

add(new CheckboxField("test " , false, checkBoxStyle | USE_ALL_WIDTH));


来源:https://stackoverflow.com/questions/7470117/align-checkbox-to-the-right-on-blackberry

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!