【问题标题】:SWT Table not scrolling with mouse wheelSWT 表不使用鼠标滚轮滚动
【发布时间】:2017-04-22 22:52:56
【问题描述】:

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

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

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

  1. 列标题滚动到视图之外
  2. 即使在焦点上,我也无法使用鼠标滚轮滚动。

我真的需要自己添加吗?

ETA 更详细:

我将我的表格用作 MasterDetails 块的详细信息部分。

我的 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() 返回我的元素数组。被注释掉的部分是我最初的尝试,也没有成功。

【问题讨论】:

  • 我无法重现您的问题。我得到固定的标题,我可以用鼠标滚轮滚动。您使用的是哪个操作系统?您可以在创建表的位置发布完整的代码 sn-p 吗?
  • @Baz 我添加了代码。你现在能重现它吗?
  • @Baz 我在 Windows 7 上,Eclipse Juno
  • 不,无法重现。 Here 是我通常做的。工作得很好。不过我没有使用 RCP。
  • 这可能与我的主/详细信息块的设置方式有关吗?当焦点位于主部分(树视图)上时,它滚动得很好。另外,我注意到当列表很长时,水平滚动条(如果有的话)一直在底部,我必须一直向下滚动才能看到它。

标签: java swt


【解决方案1】:

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

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

我从here得到了提示

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-23
    • 1970-01-01
    • 2013-04-20
    • 1970-01-01
    • 2011-09-29
    • 2018-04-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多