如何获得过滤后的模型?
我正在使用 JTables 来显示用户可以过滤的信息,如果用户在过滤后保存,我想将过滤后的表保存到文本文件中以实现持久性(这意味着任何被过滤掉的内容都不会保存到文本文件中)。
对于过滤,我只是按照本教程的过滤部分进行操作: http:// /download.oracle.com/javase/tutorial/uiswing/components/table.html#sorting 它工作正常,但我不确定有什么方法可以获取当前显示的模型到包含尚未过滤掉的所有内容的基础模型。
有什么办法可以用我过滤的方式来做到这一点吗?
谢谢!
I'm working with JTables to display information that users can filter, and if the user saves after filtering I want to save the filtered table to a textfile for persistence (meaning anything that got filtered out will not be saved to the textfile).
For filtering I just followed the filtering part of this tutorial: http://download.oracle.com/javase/tutorial/uiswing/components/table.html#sorting and it works fine, but I'm not sure of any way that I can get a model of the current display as opposed to the underlying model that contains everything that hasn't been filtered out.
Is there any way to do this with this with the way that I'm filtering?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
询问表的行数(使用
getRowCount()
),这将返回过滤的(可见)行数。从 0 迭代到 rowCount,使用convertRowIndexToModel()
将每个行索引转换为模型索引,并向模型询问每个模型索引处的数据以构建已过滤(可见)数据的列表。Ask the table its number of rows (using
getRowCount()
), which will return the number of filtered (visible) rows. Iterate from 0 to the rowCount, convert each row index to the model index usingconvertRowIndexToModel()
, and ask your model the data at each model index to build the list of filtered (visible) data.此代码展示了如何执行此操作。请注意,按下按钮后,B 行不会打印到输入中。
This code shows how to do this. Please note that B row is not printed to the input after the button is pressed.