Eclipse RCP - JFace对话框不显示按钮

时间:2022-02-06 00:15:50

I'm trying to create a custom dialog with a TableViewer inside it. It looks good as Test/Preview but when I actually run my app the buttons at the bottom disappear.

我正在尝试使用其中的TableViewer创建自定义对话框。它看起来像Test / Preview,但是当我实际运行我的应用程序时,底部的按钮消失了。

Test/preview when running from inside WindowBuilder looks like this (at the bottom):

从WindowBuilder内部运行时的测试/预览看起来像这样(在底部):

Eclipse RCP  -  JFace对话框不显示按钮

When running in the app it looks like this:

在应用程序中运行时,它看起来像这样:

Eclipse RCP  -  JFace对话框不显示按钮

Here is the source code of the dialog:

这是对话框的源代码:

@Override
protected Control createDialogArea(Composite parent) {
    Composite container = (Composite) super.createDialogArea(parent);
    container.setLayout(new GridLayout(1, false));

    Composite composite = new Composite(container, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    TableColumnLayout tcl_composite = new TableColumnLayout();
    composite.setLayout(tcl_composite);

    TableViewer tableViewer = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION);
    table = tableViewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    TableViewerColumn tableViewerColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    TableColumn tblclmnNewColumn = tableViewerColumn.getColumn();
    tcl_composite.setColumnData(tblclmnNewColumn, new ColumnPixelData(150, true, true));
    tblclmnNewColumn.setText("New Column");
    table.getShell().setSize(710, 400);
    return container;
}

1 个解决方案

#1


Don't call setSize on the Shell you are overriding the size calculated by the layout and causing the buttons to be outside of the dialog.

不要在Shell上调用setSize,而是覆盖布局计算的大小并使按钮位于对话框之外。

To control the size of the table set height and width hints on the table grid data:

要控制表格大小,请设置表格网格数据的高度和宽度提示:

GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
data.widthHint = 710;
data.heightHint = 400;
table.setLayoutData(data);

#1


Don't call setSize on the Shell you are overriding the size calculated by the layout and causing the buttons to be outside of the dialog.

不要在Shell上调用setSize,而是覆盖布局计算的大小并使按钮位于对话框之外。

To control the size of the table set height and width hints on the table grid data:

要控制表格大小,请设置表格网格数据的高度和宽度提示:

GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
data.widthHint = 710;
data.heightHint = 400;
table.setLayoutData(data);