내가 옵션 세트에서 필터링에 대처하기 위해 자신의 Matcher
의 구현에 좋은 참조로 Custom MatcherEditor screencast 당신을 가리킬 것이다.
핵심 부분은 MatcherEditor
의 생성입니다.이 경우에는 국적 별 사람들 표를 필터링합니다. 이 MatcherEditor
그것이 TextMatcherEditor
의 비슷로서 너무 익숙하지 않아야 사용되는 방법
private static class NationalityMatcherEditor extends AbstractMatcherEditor implements ActionListener {
private JComboBox nationalityChooser;
public NationalityMatcherEditor() {
this.nationalityChooser = new JComboBox(new Object[] {"British", "American"});
this.nationalityChooser.getModel().setSelectedItem("Filter by Nationality...");
this.nationalityChooser.addActionListener(this);
}
public Component getComponent() {
return this.nationalityChooser;
}
public void actionPerformed(ActionEvent e) {
final String nationality = (String) this.nationalityChooser.getSelectedItem();
if (nationality == null)
this.fireMatchAll();
else
this.fireChanged(new NationalityMatcher(nationality));
}
private static class NationalityMatcher implements Matcher {
private final String nationality;
public NationalityMatcher(String nationality) {
this.nationality = nationality;
}
public boolean matches(Object item) {
final AmericanIdol idol = (AmericanIdol) item;
return this.nationality.equals(idol.getNationality());
}
}
}
: 위의 샘플 JComboBox
에서
EventList idols = new BasicEventList();
NationalityMatcherEditor nationalityMatcherEditor = new NationalityMatcherEditor();
FilterList filteredIdols = new FilterList(idols, nationalityMatcherEditor);
선언과 MatcherEditor
자체에서 시작된다. 추적중인 객체에 대한 참조가 필요하지만 정확하게 스타일을 따를 필요는 없습니다. 나를 위해, 내가 스윙 컨트롤을보고 있다면 나는 폼의 나머지 부분을 선언하고 시작하는 경향이있다.
....
private JComboBox nationalityChooser;
public NationalityMatcherEditor(JComboBox alreadyConfiguredComboBox) {
this.nationalityChooser = alreadyConfiguredComboBox;
}
....