java swt TitleAreaDialog 添加滚动条

本文档详细介绍了如何在Java SWT中创建一个TitleAreaDialog,并且添加了水平和垂直滚动条,以适应包含多个按钮和标签的布局。通过设置布局数据和ScrolledComposite的属性,确保了滚动条的显示和内容的自适应调整。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 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;
 }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值