滚动复合的Jface对话框 [英] Jface dialog with ScrolledComposite

查看:99
本文介绍了滚动复合的Jface对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to display scrollable composite in my dialog window.

但是没有滚动条。我也没有得到确定取消按钮。

But it do not get the scrollbars. I also don't get the "OK" "Cancel" buttons.

如何解决?

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;  


  }

推荐答案

我几乎得到了工作。但是,在底部有一些空白的对话框按钮。如果这不打扰你,或者你要添加按钮,下面的代码会做你想要的。如果没有,我不知道如何帮助你。

Ok, so I almost got it working. However, at the bottom there is some empty space where the dialog buttons would be. If this doesn't bother you, or you are going to add buttons, the code below will do what you want. If not, I don't know how to help you.

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

但是,我假设您将使用对话框按钮。否则你可以简单地使用一个复合的shell,如我之前发布的例子所见。

However, I assume you are going to use dialog buttons. Otherwise you could simply use a shell with a composite as seen in the example I posted before...

这篇关于滚动复合的Jface对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆