0

我希望能够将选项添加到 NatTable 的右键单击菜单中,单击该选项会导致隐藏行或列标题,但也可以将其恢复。

4

2 回答 2

0

我最终通过更改我的 RowHeaderDataProvider 中的 getColumnCount() 方法中的逻辑来解决这个问题,以便在标记为隐藏时返回 0,或者在标记为不隐​​藏时返回 1。这同样适用于我的 ColumnHeaderDataProvider 中的 getRowCount()。

于 2016-10-11T21:19:15.967 回答
0

常见的做法是对对应的进行操作DataLayer,修改行高。修改IDataProvider通常不是一个好习惯,因为IDataProvider它负责提供数据,而不是应该如何呈现数据。所以下面是一个如何切换列标题层可见性的例子(假设hideHeader是存储当前状态的标志)。

    Button hideButton = new Button(buttonPanel, SWT.PUSH);
    hideButton.setText("Hide/Show");
    hideButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            this.hideHeader = !this.hideHeader;
            if (this.hideHeader) {
                columnHeaderDataLayer.setDefaultRowHeight(0);
            } else {
                columnHeaderDataLayer.setDefaultRowHeight(20);
            }
            natTable.refresh(false);
        }
    });

我知道甚至使用这种方法通过将高度缓慢降低到 0 来实现某种过渡的用户。

RowResizeCommand或者,如果列标题DataLayer未知,您可以使用

    Button hideButton = new Button(buttonPanel, SWT.PUSH);
    hideButton.setText("Hide/Show");
    hideButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            this.hideHeader = !this.hideHeader;
            if (this.hideHeader) {
                natTable.doCommand(new RowResizeCommand(natTable, 0, 0));
            } else {
                natTable.doCommand(new RowResizeCommand(natTable, 0, 20));
            }
        }
    });
于 2016-10-12T06:54:55.787 回答