java 如何隐藏/删除 SWT 表中的列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6512831/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to hide/delete column in SWT table
提问by Ivan Sopov
Which approach to use to have ability to hide/delete columns in the table in SWT (in Eclipse plugin in particular)?
使用哪种方法可以在 SWT 中隐藏/删除表中的列(特别是在 Eclipse 插件中)?
- A cannot transfer this functionality to rows, since I need insert and hide(or delete) of both rows and columns.
- I tried to delete them with TableColumn.dispose(), but according ColumnWeightData in the layout was not deleted and resetting the whole table layout with new TableLayout did not delete information about the columns from the layout.
- I tried to create all the needed columns, and hide with setWidth(0) those that should be hidden/deleted. The sample code that I written is here. This approach is not good: 3.1. It does not scale. In my case the maximum quantity of columns may be several thousand with only few really needed by the user. 3.2. Dealing with resizing is really a hell. AFAIU, even after setResizable(false) column may be resized if the parent component is resized. To deal with it I need to write huge listeners for parent component. I didn't try yet.
- A 不能将此功能转移到行,因为我需要插入和隐藏(或删除)行和列。
- 我试图用 TableColumn.dispose() 删除它们,但根据布局中的 ColumnWeightData 没有被删除,并且使用新的 TableLayout 重置整个表格布局并没有从布局中删除有关列的信息。
- 我试图创建所有需要的列,并用 setWidth(0) 隐藏那些应该隐藏/删除的列。我编写的示例代码在这里。这种方法不好: 3.1。它没有规模。在我的情况下,列的最大数量可能是几千个,而用户真正需要的列数很少。3.2. 处理调整大小真的是一个地狱。AFAIU,即使在 setResizable(false) 列可以调整大小后,如果父组件被调整。为了处理它,我需要为父组件编写巨大的侦听器。我还没试。
So should I
我也应该
- Investigate disposing table columns further and use it?
- Stack with setWidth(0) for a while, as I have not met scaling issues yet?
- Look in the direction of some third-party table components (Nattable...)? - If yes, preferably open-source, as my Eclipse-plugin is open-source.
- 进一步调查处理表列并使用它?
- 与 setWidth(0) 堆叠一段时间,因为我还没有遇到缩放问题?
- 看一些第三方表格组件(Nattable...)的方向?- 如果是,最好是开源的,因为我的 Eclipse 插件是开源的。
回答by Mario Marinato
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 );
回答by the.duckman
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. Set table.setRedraw(false)
, remove the data from your Table, dispose all TableColumns, recreate the neccessary ones and set your data again. Then set table.setRedraw(true)
. This minimizes flickering.
我每次只用可见列重新创建表列。如果您使用SWT.VIRTUAL
样式位,这将相当快。设置table.setRedraw(false)
,从你的表中删除数据,处理所有的表列,重新创建必要的并再次设置你的数据。然后设置table.setRedraw(true)
。这最大限度地减少了闪烁。
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. It implicates a different handling of your Table. You might try without that first, to see if it is fast enough.
但是SWT.VIRTUAL
,不适合胆小的人使用。它意味着对您的表的不同处理。您可以先尝试不使用它,看看它是否足够快。
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
实现,我预计会出现问题。