我正在尝试在我的桌子中选择一些项目,但我不希望它们被揭示.
问题是调用方法(如下所示)会自动导致在Table.class中调用showSelected(),这不是我想要的.
问题是调用方法(如下所示)会自动导致在Table.class中调用showSelected(),这不是我想要的.
tableViewer.getTable().setSelection(lastSelectedindices);
我已经尝试使用tableViewer设置选择,但由于某种原因它不起作用
例如:tableViewer.setSelection(new StructuredSelection(lastSelectedindices),false);
这行代码不会导致任何选择.
无论如何我可以选择表格行而不是让它们被揭示?
在我的系统中,每次网格刷新后我都需要调用setSelection,这样用户就不会丢失他选择的项目.当用户向下滚动网格时出现问题 – >如果在该点发生刷新,则网格会跳回到所选项目所在的位置.当用户向下滚动一个表并突然滚动条跳到顶部时,它看起来很奇怪.
任何帮助是极大的赞赏!
– 用于设置表格的代码 –
// add table viewer tableViewer = new TableViewer(this,SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL); tableViewer.setUseHashlookup(true); tableViewer.addFilter(new GridPanelViewerFilter()); tableViewer.setComparator(new GridPanelViewerComparator()); tableViewer.setComparer(new GridPanelElementComparer()); table = tableViewer.getTable(); GridData tableGd = new GridData(SWT.FILL,SWT.FILL,true,true); table.setLayoutData(tableGd); table.setHeaderVisible(true); table.setLinesVisible(true); // set table font setTableFont(); // listen to paint events for anti aliasing table.addPaintListener( ...etcetc
—刷新表的代码 –
protected void refreshGrid() { if(!updateGrid) return; display.getDefault().asyncExec(new Runnable() { @Override public void run() { try { // check if disposed if (isdisposed()) { log.log(new Status(IStatus.ERROR,Activator.PLUGIN_ID,getClass().getName() + ": " + "Grid already disposed")); return; } // refresh table table.setRedraw(false); try { // get last selected indices from mouse down event tableViewer.refresh(true,false); if(lastSelectedindices != null){ tableViewer.getTable().deselectAll(); tableViewer.getTable().select(lastSelectedindices); } } catch (Exception e) { log.log(new Status(IStatus.ERROR,getClass().getName() + ": " + "Error at refresh table",e)); } table.setRedraw(true); // process post grid refresh postGridRefresh(); } catch (Exception e) { log.log(new Status(IStatus.ERROR,getClass().getName() + ": " + "Error during refresh grid",e)); } } }); }
解决方法
尝试使用Table.select(索引)来防止泄露.
但是使用TableViewer.refresh()实际上应该保留选择.只是一个疯狂的猜测,但也许你在TableViewer上设置任何输入之前尝试TableViewer.setUseHashlookup(true).
你使用VIRTUAL表吗?如果是这样,请先尝试不使用VIRTUAL标志.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。