[英]How to hide/delete column in SWT table
Which approach to use to have ability to hide/delete columns in the table in SWT (in Eclipse plugin in particular)? 使用哪种方法来隐藏/删除SWT中的列(特别是在Eclipse插件中)?
So should I 我也应该这样
We do that on many of our tables here. 我们在这里的许多表格上都是这样做的。
First, we make sure the user does not see what we're doing. 首先,我们确保用户不会看到我们正在做的事情。
table.setRedraw( false );
Then we remove all columns. 然后我们删除所有列。
while ( table.getColumnCount() > 0 ) {
table.getColumns()[ 0 ].dispose();
}
And then we add the needed ones. 然后我们添加所需的那些。
ArrayList<Column> columns = getShownColumns();
for ( Column column : columns ) {
TableColumn tableColumn = new TableColumn( table, column.getStyle() );
tableColumn.setText( column.getTitle() );
tableColumn.setWidth( column.getWidth() );
}
And finally we let the user see what we did. 最后,我们让用户看到我们做了什么。
table.setRedraw( true );
I'd recreate the table columns each time with the visible columns only. 我每次只使用可见列重新创建表列。 If you use the SWT.VIRTUAL
style bit, this will be reasonably fast. 如果使用SWT.VIRTUAL
样式位,则速度相当快。 Set table.setRedraw(false)
, remove the data from your Table, dispose all TableColumns, recreate the neccessary ones and set your data again. 设置table.setRedraw(false)
,从表中删除数据,处理所有TableColumns,重新创建必要的数据并重新设置数据。 Then set table.setRedraw(true)
. 然后设置table.setRedraw(true)
。 This minimizes flickering. 这最大限度地减少了闪烁。
I did all this, it worked fine, the disposal of the TableColumns worked as expected. 我做了所有这些,它工作正常,TableColumns的处理按预期工作。
Using SWT.VIRTUAL
is not for the faint-hearted, though. 但是,使用SWT.VIRTUAL
不适合胆小的人。 It implicates a different handling of your Table. 它暗示了对表的不同处理。 You might try without that first, to see if it is fast enough. 你可以先试试,看看它是否足够快。
Having a table with thousands of columns and only showing a few to the user sounds very strange to me. 拥有一个包含数千列的表格,只向用户显示一些内容对我来说非常奇怪。 With the native Table
implementations I expect issues with that. 使用本机Table
实现,我预计会遇到问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.