如何获得过滤后的模型? [英] How can I get the filtered model?

查看:171
本文介绍了如何获得过滤后的模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JTables显示用户可以过滤的信息,如果用户在过滤后保存,我想将过滤后的表保存到文本文件中以保持持久性(意味着任何过滤掉的内容都不会保存到文本文件中) )。

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).

对于过滤,我只是按照本教程的过滤部分进行操作: http://download.oracle.com/javase/tutorial/uiswing/components/table.html#sorting 它工作正常,但我是不确定我是否可以获得当前显示的模型,而不是包含尚未过滤掉的所有内容的基础模型。

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?

谢谢!

推荐答案

询问表的行数(使用 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 using convertRowIndexToModel(), and ask your model the data at each model index to build the list of filtered (visible) data.

这篇关于如何获得过滤后的模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆