是否可以在SWT中顶部对齐复选框

时间:2014-02-20 13:15:58

标签: java checkbox swt

是否可以在SWT中顶部对齐复选框符号?目前垂直居中的复选框符号。但我想把它放在首位。

enter image description here

由于

1 个答案:

答案 0 :(得分:1)

有可能:

public class Test {

    public static void main(String[] args) {
        Display display = new Display();

        Shell shell = new Shell(display);
        shell.setMinimumSize(1, 1);
        shell.setLayout(new GridLayout(2, false));

        Composite left = new Composite(shell, SWT.NONE);
        left.setLayout(new GridLayout(1, false));
        GridData gd = new GridData();
        gd.verticalAlignment = SWT.TOP;
        left.setLayoutData(gd);

        new Button(left, SWT.CHECK);

        Composite right = new Composite(shell, SWT.NONE);
        right.setLayout(new GridLayout(1, false));
        Label label = new Label(right, SWT.WRAP);
        label.setText("Lorem inpsum. Lorem inpsum. Lorem inpsum.\n Lorem inpsum. Lorem inpsum. Lorem inpsum. \nLorem inpsum. Lorem inpsum.\n Lorem inpsum. Lorem inpsum. Lorem inpsum. Lorem inpsum. Lorem inpsum. Lorem inpsum.\n Lorem inpsum. Lorem inpsum. Lorem inpsum.\n Lorem inpsum. Lorem inpsum. ");
        GridData gd2 = new GridData();
        gd2.verticalAlignment = SWT.TOP;
        label.setLayoutData(gd2);

        shell.pack();
        shell.open();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
    }
}

如果您有另一种创建小部件的方法,并且希望按照您的描述使其正常工作,则需要发布一些代码段。