java swt TitleAreaDialog 添加滚动条

来源:互联网 发布:c语言取反操作符 编辑:程序博客网 时间:2024/05/13 22:33

 protected Control createDialogArea(Composite parent) {
  Composite area = (Composite) super.createDialogArea(parent);
  
  ScrolledComposite scrolledComposite = new ScrolledComposite(area, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
  GridData gridData = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1);
  gridData.heightHint = 205;//可调节大小,不可缺少
  scrolledComposite.setLayoutData(gridData);
  scrolledComposite.setExpandHorizontal(true);
  scrolledComposite.setExpandVertical(true);
  scrolledComposite.setAlwaysShowScrollBars(true);


  Composite container = new Composite(scrolledComposite, SWT.NONE);
  container.setLayout(new FillLayout(SWT.HORIZONTAL));
  
  Composite composite = new Composite(container, SWT.NONE);
  composite.setLayout(new GridLayout(2, false));
  
  Label label = new Label(composite, SWT.NONE);
  label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
  label.setText("New Label");
  
  Button button = new Button(composite, SWT.NONE);
  button.setText("New Button1");
  
  Label label_1 = new Label(composite, SWT.NONE);
  label_1.setText("New Label2");
  
  Button button_1 = new Button(composite, SWT.NONE);
  button_1.setText("New Button2");
  
  Label label_2 = new Label(composite, SWT.NONE);
  label_2.setText("New Label");
  
  Button button_2 = new Button(composite, SWT.NONE);
  button_2.setText("New Button3");
  
  Label label_3 = new Label(composite, SWT.NONE);
  label_3.setText("New Label");
  
  Button button_3 = new Button(composite, SWT.NONE);
  button_3.setText("New Button4");
  
  Label label_5 = new Label(composite, SWT.NONE);
  label_5.setText("New Label");
  
  Button button_4 = new Button(composite, SWT.NONE);
  button_4.setText("New Button5");
  
  Label label_4 = new Label(composite, SWT.NONE);
  label_4.setText("New Label");
  
  Button button_5 = new Button(composite, SWT.NONE);
  button_5.setText("6");
  
  Label label_6 = new Label(composite, SWT.NONE);
  label_6.setText("New Label");
  
  Button button_6 = new Button(composite, SWT.NONE);
  button_6.setText("New Button7");
  
  Label label_7 = new Label(composite, SWT.NONE);
  label_7.setText("New Label");
  
  Button button_7 = new Button(composite, SWT.NONE);
   button_7.setText("New Button8");
  
  Label label_8 = new Label(composite, SWT.NONE);
  label_8.setText("New Label");
  
  Button button_8 = new Button(composite, SWT.NONE);
  button_8.setText("New Button9");
  
  scrolledComposite.setContent(container);
  scrolledComposite.setMinSize(container.computeSize(SWT.DEFAULT, SWT.DEFAULT));

  return area;
 }

 

原创粉丝点击