2012-09-30 50 views
1

我想在我的對話框窗口中顯示可滾動的組合。與ScrolledComposite的Jface對話框

但它沒有得到滾動條。我也沒有得到「確定」「取消」按鈕。

如何解決?

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; 


    } 

enter image description here

回答

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

enter image description here

然而,我假設你打算使用對話框按鈕。否則,您可以簡單地使用帶有複合的外殼,如前面發佈的示例中所示...

+0

這不會幫助 – user1658192

+0

@ user1658192此外刪除此行:'newShell.setSize(200,100);' – Baz

+0

否,這是對話框的大小。它應該是固定的。 – user1658192