shell采用(垂直的)填充式布局。
shell中的Composite面板采用GridLayout布局。
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
public class C{
public static void main(String[] args){
Display display=new Display();
Shell shell=new Shell(display);
shell.setText("布局指的是里面的控件如何放置的");
//理解:GridLayout是布局,GridData是设置一个控件的大小
//(1)设置shell的布局。指的是shell中的控件是如何放置的。
shell.setLayout(new FillLayout(SWT.VERTICAL));
//在shell中放置一个面板和一个按钮
Composite composite=new Composite(shell,SWT.NONE);
//面板中放置文本框控件
Text[] textArray=new Text[10];
for(int i=0;i<textArray.length;i++){
textArray[i]=new Text(composite,SWT.MULTI);
textArray[i].setText("这是第"+i+"个文本框");
}
//(2)设置面板的布局。指的是面板中的控件是如何放置的。
composite.setLayout(new GridLayout());
Button button=new Button(shell,SWT.PUSH);
button.setText("显示下一个文本框");
//打开窗口,进行窗口的显示
shell.setSize(400,600);
//shell.pack();
shell.open();
while(!shell.isDisposed()){
//当窗口没有被释放的时候
if(!display.readAndDispatch()){
display.sleep();
}
}
display.dispose();
}
}