kev*_*vin 2 java checkbox swt alignment
如何在我的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:");
Run Code Online (Sandbox Code Playgroud)
它看起来如下:
[ ] I need the complete ECR/ECN Process:
Run Code Online (Sandbox Code Playgroud)
我希望它看起来像:
I need the complete ECR/ECN Process: [ ]
Run Code Online (Sandbox Code Playgroud)
你不能只使用一个Button
控件,你需要使用一个Label
文本和一个复选框Button
,没有文本排列在两列.
就像是:
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 ....
Run Code Online (Sandbox Code Playgroud)
有一次,我有点不同意格雷格.
您可以使用setOrientation(int)
的方法Button
来强制从右到左的布局:
public static void main(String[] args)
{
Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new GridLayout());
Button button = new Button(shell, SWT.CHECK);
button.setText("TEST");
button = new Button(shell, SWT.CHECK);
button.setOrientation(SWT.RIGHT_TO_LEFT);
button.setText("TEST");
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
{
display.sleep();
}
}
display.dispose();
}
Run Code Online (Sandbox Code Playgroud)
看起来像这样:
(在Linux Mint和Windows上测试.在Mac上不起作用.)