我编写了一个小程序,它有 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();}实际输出:预期输出:
添加回答
举报
0/150
提交
取消