繁体   English   中英

具有ScrolledComposite的Jface对话框

[英]Jface dialog with ScrolledComposite

我正在尝试在我的对话框窗口中显示可滚动合成。

但是它没有滚动条。 我也没有“确定”“取消”按钮。

如何解决?

public class MyDialog extends Dialog {

  public MyDialog (Shell parentShell) {
    super(parentShell);     
  }

   protected void configureShell(Shell newShell) {
    super.configureShell(newShell);
    newShell.setText("test");
    newShell.setSize(200, 100);
  }

  protected Control createDialogArea(Composite parent) {
         ScrolledComposite sc = new ScrolledComposite(parent, SWT.H_SCROLL |    SWT.V_SCROLL | SWT.BORDER);


    Composite composite = new Composite(sc, SWT.NONE);
    composite.setLayout(new FillLayout(SWT.VERTICAL));

    new Label(composite, SWT.NONE).setText("1111");
    new Label(composite, SWT.NONE).setText("2222");
    new Label(composite, SWT.NONE).setText("3333");
    new Label(composite, SWT.NONE).setText("4444");
    new Label(composite, SWT.NONE).setText("5555");
    new Label(composite, SWT.NONE).setText("6666");
    new Label(composite, SWT.NONE).setText("7777");

    sc.setContent(composite);
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);


    return parent;  


  }

在此处输入图片说明

好的,所以我几乎可以正常工作了。 但是,在底部,对话框按钮将保留一些空白。 如果这不打扰您,或者您要添加按钮,则下面的代码将满足您的要求。 如果没有,我不知道该如何帮助您。

public class MyDialog extends Dialog
{

    protected MyDialog(Shell parentShell) {
        super(parentShell);
    }

    protected void configureShell(Shell newShell) {
        super.configureShell(newShell);
        newShell.setText("test");
        newShell.setSize(200, 100);
    }

    protected void createButtonsForButtonBar(Composite parent) {
    }

    protected Control createDialogArea(Composite parent) {
        Composite content = (Composite) super.createDialogArea(parent);
        content.setLayout(new FillLayout());

        ScrolledComposite sc = new ScrolledComposite(content, SWT.H_SCROLL
                | SWT.V_SCROLL | SWT.BORDER);

        Composite composite = new Composite(sc, SWT.NONE);
        composite.setLayout(new FillLayout(SWT.VERTICAL));

        new Label(composite, SWT.NONE).setText("1111");
        new Label(composite, SWT.NONE).setText("2222");
        new Label(composite, SWT.NONE).setText("3333");
        new Label(composite, SWT.NONE).setText("4444");
        new Label(composite, SWT.NONE).setText("5555");
        new Label(composite, SWT.NONE).setText("6666");
        new Label(composite, SWT.NONE).setText("7777");

        sc.setContent(composite);
        sc.setExpandHorizontal(true);
        sc.setExpandVertical(true);
        sc.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));

        return parent; 
      }
}

在此处输入图片说明

但是,我假设您将使用对话框按钮。 否则,您可以简单地使用带有复合材料的外壳,如我之前发布的示例所示...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM