如果您查看 and 的 Javadoc GridData.HORIZONTAL_ALIGN_BEGINNING
,GridData.VERTICAL_ALIGN_BEGINNING
您会看到它说:
不推荐。改用 new GridData( SWT.BEGINNING , int, boolean, boolean) 。
和
不推荐。改用 new GridData(int, SWT.BEGINNING , boolean, boolean) 。
始终使用SWT
对齐常量:
public static void main(String[] args)
{
Display display = Display.getDefault();
final Shell shell = new Shell(display);
shell.setText("StackOverflow");
shell.setLayout(new GridLayout(2, false));
Label left = new Label(shell, SWT.BORDER);
left.setText("LEFT");
Label right = new Label(shell, SWT.BORDER);
right.setText("RIGHT\nRIGHT\nRIGHT\nRIGHT");
GridData data = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false);
left.setLayoutData(data);
data = new GridData(SWT.FILL, SWT.FILL, true, true);
right.setLayoutData(data);
shell.pack();
shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
看起来像这样: