1

ダイアログ ウィンドウにスクロール可能なコンポジットを表示しようとしています。

しかし、スクロールバーは取得できません。また、「OK」「キャンセル」ボタンも表示されません。

修正方法は?

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;  


  }

ここに画像の説明を入力

4

1 に答える 1

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

ここに画像の説明を入力

ただし、ダイアログ ボタンを使用することを想定しています。それ以外の場合は、前に投稿した例に見られるように、コンポジットでシェルを単純に使用できます...

于 2012-09-30T11:42:59.280 に答える