如何正确对齐Java SWT应用程序中的复选框

时间:2015-08-13 18:34:08

标签: java checkbox alignment swt

如何正确对齐Java SWT应用程序中的复选框?这是我的代码片段:

    Button checkFullECR = new Button(scrolledForm.getBody(), SWT.CHECK);
    checkFullECR.setAlignment(SWT.RIGHT);
    checkFullECR.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
    checkFullECR.setText("I need the complete ECR/ECN Process:");

如下所示:

[ ] I need the complete ECR/ECN Process:

我希望它看起来像:

I need the complete ECR/ECN Process:       [ ]

1 个答案:

答案 0 :(得分:5)

仅使用Button控件无法执行此操作,您需要使用Label作为文本,使用复选框Button,不要将文字排列在两列中。< / p>

类似的东西:

Composite body = new Composite(parent, SWT.NONE);

body.setLayout(new GridLayout(2, false));

Label label = new Label(body, SWT.LEFT);
label.setText("I need the complete ECR/ECN Process:");

Button checkFullECR = new Button(body, SWT.CHECK);

... more label / button pairs ....