Tôi đang sử dụng bố cục lưới trong vỏ. Tôi muốn kiểm soát vị trí của các vật dụng. Như bạn có thể thấy các nút dưới cùng phải ở trên hàng 4. Tôi đang sử dụng plugin trình xây dựng cửa sổ và có thể đặt chúng ở những vị trí mong muốn.Cách đặt hàng và cột của tiện ích trong bố cục lưới?
Vấn đề là tôi không thể xem hướng dẫn vị trí trong mã nguồn. Làm thế nào tôi có thể đặt chúng theo cách có lập trình. Đây là trình tạo cửa sổ mã nguồn tạo ra.
package dgsj.Chapter04.examples.ch4;
import org.eclipse.swt.widgets.*;
public class GridLayout2x2 {
private static GridData data_1;
private static GridData data_2;
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setMinimumSize(new Point(123, 30));
shell.setSize(126, 123);
GridLayout layout = new GridLayout();
layout.numColumns = 3;
shell.setLayout(layout);
GridData data = new GridData(GridData.FILL_BOTH);
data.grabExcessHorizontalSpace = false;
data.widthHint = 200;
data.grabExcessVerticalSpace = false;
Button one = new Button(shell, SWT.PUSH);
one.setText("one");
one.setLayoutData(data);
data = new GridData(GridData.FILL_BOTH);
Button two = new Button(shell, SWT.PUSH);
two.setText("two");
two.setLayoutData(data);
new Label(shell, SWT.NONE);
new Label(shell, SWT.NONE);
data_2 = new GridData(GridData.FILL_BOTH);
Button four = new Button(shell, SWT.PUSH);
four.setText("four");
four.setLayoutData(data_2);
new Label(shell, SWT.NONE);
new Label(shell, SWT.NONE);
new Label(shell, SWT.NONE);
new Label(shell, SWT.NONE);
new Label(shell, SWT.NONE);
Button btnNewButton = new Button(shell, SWT.NONE);
btnNewButton.setText("New Button");
data_1 = new GridData(GridData.FILL_BOTH);
data_1.grabExcessVerticalSpace = false;
data_1.grabExcessHorizontalSpace = false;
Button three = new Button(shell, SWT.PUSH);
three.setText("three");
three.setLayoutData(data_1);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
Liệu các "tế bào" trống đó lưới phải chứa bất kỳ thông tin nào khác? –
Trong một số giao diện, chúng hoàn toàn trống và mục đích duy nhất của chúng là điều chỉnh bố cục. Trong một số chế độ xem khác, có một nhãn xác thực hiển thị một số lỗi. –