猿问

对齐按钮中的 SWT 问题

我编写了一个小程序,它有 2 个列表视图和一个用于选择和取消选择所选组合的按钮。问题是我无法将按钮与列的中心对齐。


public static void main(String[] args) {

    Display display = new Display();

    Shell shell = new Shell(display);

    shell.setLayout(new FillLayout());

    shell.setLayout(new GridLayout(3, true));

    GridData data = new GridData(GridData.FILL_BOTH);


    // Creating Label

    new Label(shell, SWT.NONE).setText("This is a plain Text");

    new Label(shell, SWT.NONE).setText("");

    new Label(shell, SWT.NONE).setText("This is a plain Text");

    // Create a single-selection list

    List single = new List(shell, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL);

    single.setLayoutData(data);


    // Add the items, one by one

    for (int i = 0, n = ITEMS.length; i < n; i++) {

        single.add(ITEMS[i]);

    }

    single.setSelection(0);


    //////////////////////////////////////////////////////

    // Button button1=new Button(shell, SWT.ARROW | SWT.RIGHT);


    Group first = new Group(shell, SWT.CENTER);

    first.setLayout(new RowLayout(SWT.VERTICAL));

    Button button1 = new Button(first, SWT.NONE);


    // GridData bdata = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);


    Button button3 = new Button(first, SWT.PUSH);

    // button3.setLayoutData(bdata);

    button1.setText("Select    ");

    button3.setText("UnSelect");


    //////////////////////////////////////////////

    // Create a single-selection list

    List single2 = new List(shell, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL);

    single2.setLayoutData(data);

    single2.add("");


    single2.setSelection(0);


    shell.open();


    System.out.println(single.getItem(single.getSelectionIndex()));


    while (!shell.isDisposed()) {

        if (!display.readAndDispatch()) {

            display.sleep();

        }

    }

    display.dispose();

}

实际输出:

预期输出:

http://img3.mukewang.com/60eeb8d7000179a614200723.jpg

BIG阳
浏览 172回答 1
1回答
随时随地看视频慕课网APP

相关分类

Java
我要回答