import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.layout.*;
public class A{
public static void main(String[] args){
Display display=new Display();
Shell shell=new Shell(display);
shell.setText("滚动面板ScrolledComposite");
//滚动面板:带有垂直滚动条和水平滚动条的面板
FillLayout layout1=new FillLayout();
layout1.marginHeight=20;
layout1.marginWidth=20;
shell.setLayout(layout1);//必须要有
//shell.setLayout(new FillLayout(SWT.HORIZONTAL));//必须要有
//创建一个滚动面板对象,有边框,水平滚动,垂直滚动
ScrolledComposite sc=new ScrolledComposite(shell,SWT.H_SCROLL|SWT.V_SCROLL|SWT.BORDER);
//创建一个普通的面板放在滚动面板中
Composite c=new Composite(sc,SWT.NONE);
GridLayout layout=new GridLayout();
layout.numColumns=6;//列数是6
c.setLayout(layout);
for(int i=0;i<20;i++){
Button bt=new Button(c,SWT.PUSH);
bt.setText("按钮"+i);
c.setSize(c.computeSize(SWT.DEFAULT, SWT.DEFAULT));
//c.setSize(50,80);//错误的
}
//将普通面板设置为受控的滚动面板
sc.setContent(c);
//设置某一个控件受控于滚动面板的方法setContent(Control content)
//打开窗口,进行窗口的显示
shell.setSize(300,200);
//shell.pack();
shell.open();
while(!shell.isDisposed()){
//当窗口没有被释放的时候
if(!display.readAndDispatch()){
display.sleep();
}
}
display.dispose();
}
}
import org.eclipse.swt.SWT;
import org.e