我正在尝试创建一个带有TableViewer的自定义对话框。看起来像“测试/预览”一样不错,但是当我实际运行我的应用程序时,底部的按钮消失了。

从WindowBuilder内部运行时的测试/预览如下所示(在底部):



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



这是对话框的源代码:

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

最佳答案

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

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

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

关于java - Eclipse RCP-“JFace”对话框不显示按钮,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30192965/

10-16 09:15