简体   繁体   English

在Swing中使用行过滤Jtable

[英]using row to filter Jtable in Swing

I want to filter the content of my Jtable with different Textfields in a header row but I don't know how do it. 我想用标题行中的不同Textfield过滤我的Jtable的内容,但是我不知道该怎么做。

My idea is use TextField as cell editor for the first Row (the unique editable row of my table). 我的想法是使用TextField作为第一行(表的唯一可编辑行)的单元格编辑器。 My first problem is that don't know how define this row with a setCellEditor method, I think this method only serves to define the column editor object. 我的第一个问题是,不知道如何使用setCellEditor方法定义该行,我认为该方法仅用于定义列编辑器对象。

Any idea as how do it? 有什么想法吗?

Then I belive that I will have other problem: How do I order my table without lose my filter row? 然后我相信我还会遇到其他问题:如何在不丢失过滤器行的情况下排序表?

How do I order my table without lose my filter row? 如何在不丢失过滤器行的情况下订购表?

Don't use data in the table as a filter row. 请勿将表格中的数据用作过滤器行。

Instead create separate text fields above the table to use as the fllter. 而是在表格上方创建单独的文本字段,以用作过滤器。 Read the section from the Swing tutorial of Sorting and Filtering for a working example. 阅读Swing的Sorting and Filtering教程中的部分,获取一个工作示例。

Filtering if you mean to show Table data based on keywords enter in the JTextfield based header, then you can simply work with Table Model to achieve the same. 如果要在基于JTextfield的标题中输入基于关键字的表数据以进行过滤,则可以简单地与表模型一起使用以实现相同的目的。

if you want to sort the content , use Sorter for the same. 如果要对内容进行排序,请使用Sorter进行相同的操作。 http://www.java2s.com/Code/Java/Swing-JFC/JTablesorterclickthetableheadertosortacolumnandatable.htm http://www.java2s.com/Code/Java/Swing-JFC/JTablesorterclickthetableheadertosortacolumnandatable.htm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM