Java 如何将两个不同级别的过滤器添加到同一个GlazedList表中?
我已经创建了一个表,我想在两个不同的级别对其进行过滤。 首先使用文件扩展名上的单选按钮对其进行过滤,如(.jpg、.doc,其余)。 第二个过滤器,它与textField搜索内容内的第一个过滤。 如下所示,您可以在演示中看到,我可以使用单选按钮过滤表,但我不知道如何在表上应用二级过滤器(JTextField) 有人知道怎么做吗?Java 如何将两个不同级别的过滤器添加到同一个GlazedList表中?,java,swing,filter,glazedlists,Java,Swing,Filter,Glazedlists,我已经创建了一个表,我想在两个不同的级别对其进行过滤。 首先使用文件扩展名上的单选按钮对其进行过滤,如(.jpg、.doc,其余)。 第二个过滤器,它与textField搜索内容内的第一个过滤。 如下所示,您可以在演示中看到,我可以使用单选按钮过滤表,但我不知道如何在表上应用二级过滤器(JTextField) 有人知道怎么做吗? public class TwoLevelFilterTablePanel extends OeVubPanel { private static final File
public class TwoLevelFilterTablePanel extends OeVubPanel {
private static final File DirectoryEngine = new File("C:\\Users\\Public\\Pictures\\Sample Pictures");
private JRadioButton jpg,doc,others;
private ButtonGroup radioSet;
private JTextField txtFilter;
private JTable glazedTable;
private BasicEventList<MyCode> eventList;
private JPanel filterPanel,radioSetPanel;
public TwoLevelFilterTablePanel(BasicEventList<MyCode> eventList) {
this.eventList=eventList;
createComponents();
layoutComponents();
}
public void createComponents() {
jpg = new JRadioButton("jpg");
doc= new JRadioButton("doc");
others= new JRadioButton("other");
radioSet = new ButtonGroup();
radioSet.add(jpg);
radioSet.add(doc);
radioSet.add(others);
txtFilter = new JTextField();
radioSetPanel = new JPanel();
radioSetPanel.setLayout(new BoxLayout(radioSetPanel, BoxLayout.X_AXIS));
radioSetPanel.add(jpg);
radioSetPanel.add(doc);
radioSetPanel.add(others);
filterPanel=new JPanel();
filterPanel.setLayout(new BoxLayout(filterPanel, BoxLayout.Y_AXIS));
filterPanel.add(radioSetPanel);
filterPanel.add(txtFilter);
final BarcodeMatcherEditor barcodeMatcherEditor = new BarcodeMatcherEditor(jpg,doc,others);
final FilterList filteredRadioSet = new FilterList(eventList, barcodeMatcherEditor);
// build a JTable
String[] propertyNames = new String[] {"name", "size","date"};
String[] columnLabels = new String[] {"Name", "Size","Date"};
TableFormat tf = GlazedLists.tableFormat(MyCode.class, propertyNames, columnLabels);
glazedTable = new JTable(new EventTableModel(filteredRadioSet, tf));
}
public void layoutComponents() {
setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
add(filterPanel);
add(new WebScrollPane(glazedTable));
}
public static void main(String[] args) {
BasicEventList<MyCode> eventList = new BasicEventList<MyCode>();
for(File file : DirectoryEngine.listFiles()){
eventList.add(new MyCode(file.getName(),file.length(),new Date(file.lastModified())));
}
TwoLevelFilterTablePanel demo = new TwoLevelFilterTablePanel(eventList );
JFrame frame = new JFrame();
Container cp = frame.getContentPane();
cp.add(demo);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 500);
frame.setLocation(500, 500);
frame.setVisible(true);
}
}
您只需将两个过滤器列表链接在一起:
EventList<Person> personLists = ...
...
FilterList<Person> filterListByGender = new FilterList<Person>(personList, genderMatchEditor);
FilterList<Person> filterListBySurname = new FilterList<Person>(filterByGender, textSurnameMatchEditor);
// Continue using the filterListBySurname as you usually would
...
EventList个人列表=。。。
...
FilterList filterListByGender=新的FilterList(personList,genderMatchEditor);
FilterList filterListBySurname=新的FilterList(filterByGender,文本编辑器);
//继续使用filterListBySurname,就像通常一样
...
您只需将两个过滤器列表链接在一起:
EventList<Person> personLists = ...
...
FilterList<Person> filterListByGender = new FilterList<Person>(personList, genderMatchEditor);
FilterList<Person> filterListBySurname = new FilterList<Person>(filterByGender, textSurnameMatchEditor);
// Continue using the filterListBySurname as you usually would
...
EventList个人列表=。。。
...
FilterList filterListByGender=新的FilterList(personList,genderMatchEditor);
FilterList filterListBySurname=新的FilterList(filterByGender,文本编辑器);
//继续使用filterListBySurname,就像通常一样
...