我正在尝试处理列并将新列添加到星云网格中,表中的数据不会改变我只想能够更改使用的列。
我遇到了一个错误,其中 Grid 在迭代现有列的列表但使用值“endColumnIndex”来停止循环时抛出索引超出范围异常,但 endColumnIndex 值大于新列的列表。
我相信这是由于使用了视觉范围支持,并且当前屏幕列的值在我删除它们时没有更新。
我在这里写了一个类来重现这个错误,并希望有人能解决这个问题:
import org.eclipse.nebula.jface.gridviewer.GridTableViewer;
import org.eclipse.nebula.jface.gridviewer.GridViewerColumn;
import org.eclipse.nebula.widgets.grid.GridColumn;
import org.eclipse.nebula.widgets.grid.GridItem;
import org.eclipse.nebula.widgets.grid.GridVisibleRangeSupport;
import org.eclipse.nebula.widgets.grid.GridVisibleRangeSupport.RangeChangedEvent;
import org.eclipse.nebula.widgets.grid.GridVisibleRangeSupport.VisibleRangeChangedListener;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class GridRangeChangeBug {
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.setSize(800, 800);
shell.setLayout(new GridLayout(1, true));
Button go = new Button(shell, SWT.PUSH);
go.setText("Reproduce Bug");
final GridTableViewer viewer = new GridTableViewer(shell, SWT.H_SCROLL
| SWT.V_SCROLL | SWT.BORDER);
viewer.getGrid().setLayoutData(
new GridData(SWT.FILL, SWT.FILL, true, true));
viewer.getGrid().setHeaderVisible(true);
GridVisibleRangeSupport rangeSupport = GridVisibleRangeSupport.createFor(viewer.getGrid());
rangeSupport.addRangeChangeListener(new VisibleRangeChangedListener() {
@Override
public void rangeChanged(RangeChangedEvent event) {
}
});
for (int i = 0; i < 100; i++) {
GridViewerColumn col = new GridViewerColumn(viewer, SWT.NONE);
col.getColumn().setWidth(30);
col.getColumn().setText("" + i);
}
go.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
for (GridColumn c : viewer.getGrid().getColumns()) {
c.dispose();
}
for (int i = 0; i < 10; i++) {
GridViewerColumn col = new GridViewerColumn(viewer,
SWT.NONE);
col.getColumn().setWidth(30);
col.getColumn().setText("" + i);
}
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}