2012-07-01 2 views
2

나는 내 테이블에 필터로 사용하려는 라디오 버튼을 가지고있다. 이 라디오 버튼은 내 모델 클래스에 변수를 설정합니다. 내 모델에 getter를 사용하여이 값을 검색하고이 값을 GlazedList 테이블의 필터로 사용하고 싶습니다.필터로 JTextField를 GlazedList의 문자열로 대체하는 방법은 무엇입니까?

신체가 그것을하는 방법을 알고 있습니까?

다음은 필터로 JTextField를 내 테이블 :

TextFilterator<Barcode> barcodeFilterator = new TextFilterator<Barcode>() { ... }; 
    WebTextField searchField = new WebTextField(barcodeModel.getSelectedFilter()); 
    MatcherEditor<Barcode> textMatcherEditor = new TextComponentMatcherEditor<Barcode>(searchField, barcodeFilterator); 
    FilterList<Barcode> filterList = new FilterList<Barcode>(BarcodeUtil.retrieveBarcodeEventList(files), textMatcherEditor); 
    TableFormat<Barcode> tableFormat = new TableFormat<Barcode>() { .... }; 
    EventTableModel<Barcode> tableModel = new EventTableModel<Barcode>(filterList, tableFormat); 
    barcodeTable.setModel(tableModel); 

답변

2

내가 옵션 세트에서 필터링에 대처하기 위해 자신의 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; 
} 
.... 
관련 문제