SWT表不能用鼠标滚轮滚动

时间:2015-01-15 14:01:38

标签: java swt

我正在创建一个这样的JFace表:

final Table table = new Table(parent, SWT.BORDER | SWT.FULL_SELECTION);

并期待滚动(标题固定在顶部),但我没有达到我的预期。有垂直和水平滚动条,我可以使用它滚动表格,但

  1. 列标题滚出视图
  2. 即使它处于聚焦状态,我也无法用鼠标滚轮滚动。
  3. 我真的需要自己添加吗?

    ETA更多细节:

    我使用我的表作为MasterDetails Block的详细信息部分。

    My DetailsPage类扩展了AbstractFormPart并实现了IDetailsPage。

    @Override
    public void createContents(final Composite parent) {
        final Layout layout = new FillLayout();
        parent.setLayout(layout);
        createViewer(parent);
    
    }
        private void createViewer(final Composite parent) {
            final Table table = new Table(parent, SWT.BORDER | SWT.FULL_SELECTION);
    
    //      this.viewer = new TableViewer(parent, SWT.MULTI | /*SWT.H_SCROLL | SWT.V_SCROLL |*/ SWT.FULL_SELECTION | SWT.BORDER);
            this.viewer = new TableViewer(table);
            createColumns(parent, this.viewer);
            table.setHeaderVisible(true);
            table.setLinesVisible(true);
    
            this.viewer.setContentProvider(new ArrayContentProvider());
            // get the content for the viewer, setInput will call getElements in the
            // contentProvider
            this.viewer.setInput( /createInput() );
            // make the selection available to other views
            this.editor.getSite().setSelectionProvider(this.viewer);
            ...
        }
    

    createInput()返回我的元素数组。注释掉的部分是我最初的尝试,也没有用。

1 个答案:

答案 0 :(得分:0)

我不确定为什么会这样,但是当我将详细信息页面的布局更改为GridLayout并为表格提供以下GridData时,它按预期工作。

    final GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.widthHint = 500;
    gd.heightHint = 120;
    table.setLayoutData(gd);

我从here

获得了提示