0

これで、にを追加できTableViewerましたTitleAreaDialog
私は私が抱えているレイアウトの問題のいくつかを理解しようとしています。
ダイアログウィンドウでtableViewerのレイアウトと場所を制御できますか?
現在、テーブルは右側に表示されています。
親コンポジットの中央に配置したい。
TableViewerをcreateDialogAreaメソッドの親レイアウトに追加できますか?ダイアログにコンポジットを追加し、それらがどこに移動し、どのように表示されるかを制御できるようにしたいと思います。また、私のテーブルでは、テーブルの最後に半分空の列が表示されていますが、それを削除する方法はありますか?

TableViewer付きのダイアログ

何かのようなもの:

GridData gridData = new GridData();
gridData.grabExcessHorizontalSpace = true;
gridData.horizontalAlignment = GridData.CENTER;
TableViewer d = createTableViewer(area);
d.setLayoutData(gridData);

これは私のcreateDialogAreaコードです。

protected Control createDialogArea(Composite parent) {
   final Composite area = new Composite(parent, SWT.NULL);
   final GridLayout gridLayout = new GridLayout();
   gridLayout.marginWidth = 15;
   gridLayout.marginHeight = 10;
   area.setLayout(gridLayout);

   TableViewer d = createTableViewer(area);

   return area;
}

これが私のテーブルビューアーコードです

 private TableViewer createTableViewer(Composite parent) {
    viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
    createColumns(parent, viewer);
    final Table table = viewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setInput(AplotSelectedDataTable.getInstance().getArrayData());

    // Layout the viewer
    GridData gridData = new GridData(SWT.CENTER);
    gridData.verticalAlignment = GridData.FILL;
    gridData.horizontalSpan = 2;
    gridData.grabExcessHorizontalSpace = true;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalAlignment = GridData.FILL;
    viewer.getControl().setLayoutData(gridData);
  return viewer;
 }
4

1 に答える 1

1

レイアウトの問題に役立つ小さな例を次に示します。

public class TestClass extends Dialog {

    private TableViewer viewer;

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

    protected Control createDialogArea(Composite parent) {
        final Composite area = new Composite(parent, SWT.NONE);
        final GridLayout gridLayout = new GridLayout(2, true);
        gridLayout.marginWidth = 15;
        gridLayout.marginHeight = 10;
        area.setLayout(gridLayout);

        area.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

        createButtons(area);
        createTableViewer(area);

        return area;
    }

    private void createButtons(Composite parent)
    {
        Button button1 = new Button(parent, SWT.PUSH);
        button1.setText("Button1");
        button1.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, true));

        Button button2 = new Button(parent, SWT.PUSH);
        button2.setText("Button2");
        button2.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, true));
    }

    private void createTableViewer(Composite parent) {
        viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
                | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
        createColumns(parent);
        final Table table = viewer.getTable();
        table.setHeaderVisible(true);
        table.setLinesVisible(true);

        viewer.setContentProvider(new ArrayContentProvider());

        // Layout the viewer
        GridData gridData = new GridData(SWT.CENTER, SWT.FILL, true, true);
        gridData.horizontalSpan = 2;
        table.setLayoutData(gridData);
    }

    private void createColumns(Composite parent)
    {
        TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE);
        final TableColumn column = viewerColumn.getColumn();
        column.setText("Title");
        column.setWidth(100);
        column.setResizable(true);
        column.setMoveable(false);
    }

    public static void main(String[] args) {
        Display display = Display.getDefault();
        final Shell shell = new Shell(display);

        TestClass test = new TestClass(shell);

        test.open();

        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }
}

Dialog基本的に、上部と下部の中央 に2つのボタンがある小さなボタンを作成しTableViewerます。これにより、問題を解決する方法がわかります。

于 2012-08-29T19:53:02.410 に答える