【问题标题】:Jface dialog with ScrolledComposite带有 ScrolledComposite 的 Jface 对话框
【发布时间】:2012-09-30 11:21:17
【问题描述】:

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

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

如何解决?

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;  


  }

【问题讨论】:

    标签: java eclipse swt jface


    【解决方案1】:

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

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

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

    【讨论】:

    • @user1658192 另外删除这一行:newShell.setSize(200, 100);
    • @user1658192 试试我提供的代码示例。这对你有用吗?
    • 我相信它会像你一样在没有对话框的情况下工作。我需要它在对话框中工作
    • @user1658192 我明白这一点。我正在尝试缩小您的问题范围...所以您尝试了它并且有效?
    • 这对我有用!唯一的变化是Composite content = (Composite) super.createDialogArea(parent); 为什么new Composite(...) 不起作用?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-17
    • 1970-01-01
    • 2018-05-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多