2009-07-03 3 views
2

いくつかのフィルタを持つjtableが主要な部分を占めているデザイン(GUIデザイン)フォームについて、私はいくつかのドキュメントに案内したり、アドバイスをしたりできますか?主な目標は、視覚的な混乱を避けることです。JTable複数のフィルタ設計パラダイム

+0

データはどこから来ていますか?リレーショナルデータベース? – Allan

+0

はい、DB ...私はguiの設計ガイドラインを探しています.... – tropikalista

答えて

4

私は過去に単純なTableFilterPanelを実装しました。これはテーブルの列に1つのJTextFieldを持ち、与えられたフィールドにテキストが存在するときに正規表現マッチングを実行します。私は通常、これを垂直ラベル+テキストフィールドのリストとしてレイアウトします(つまり、かなりコンパクトです)。 JTextFieldの内容を使用してRowFilterを製造する能力を提供しています私のキークラスがColumnSearcherと呼ばれ

、:私はそれぞれから「と」フィルタを構築するフィルタ設定を変更したい

protected class ColumnSearcher { 
    private final int[] columns; 
    private final JTextField textField; 

    public ColumnSearcher(int column, JTextField textField) { 
     this.columns = new int[1]; 
     this.textField = textField; 

     this.columns[0] = column; 
    } 

    public JTextField getTextField() { 
     return textField; 
    } 

    public boolean isEmpty() { 
     String txt = textField.getText(); 
     return txt == null || txt.trim().length() == 0; 
    } 

    /** 
    * @return Filter based on the associated text field's value, or null if the text does not compile to a valid 
    * Pattern, or the text field is empty/contains whitespace. 
    */ 
    public RowFilter<Object, Object> createFilter() { 
     RowFilter<Object, Object> ftr = null; 

     if (!isEmpty()) { 
      try { 
       ftr = new RegexFilter(Pattern.compile(textField.getText(), Pattern.CASE_INSENSITIVE), columns); 
      } catch(PatternSyntaxException ex) { 
       // Do nothing. 
      } 
     } 

     return ftr; 
    } 
} 

個々のフィルタ:

protected RowFilter<Object, Object> createRowFilter() { 
    RowFilter<Object, Object> ret; 
    java.util.List<RowFilter<Object, Object>> filters = new ArrayList<RowFilter<Object, Object>>(columnSearchers.length); 

    for (ColumnSearcher cs : columnSearchers) { 
     RowFilter<Object, Object> filter = cs.createFilter(); 
     if (filter != null) { 
      filters.add(filter); 
     } 
    } 

    if (filters.isEmpty()) { 
     ret = NULL_FILTER; 
    } else { 
     ret = RowFilter.andFilter(filters); 
    } 

    return ret; 
} 

私は、フィルタを更新したPropertyChangeListenerがそれに応えて、私の集計フィルタを再構築させたいとき、一般的に、私はPropertyChangeEventを発射。次に、ユーザーがテキストフィールドのいずれかを入力すると(たとえばDocumentListenerを各JTextFieldに追加することによって)、「rowFilter」PropertyChangeEventを起動することができます。

希望に役立ちます。

+0

Nice one Adamski – willcodejavaforfood

関連する問題