Terai Atsuhiro 2022-03-19 (土) 11:33:09

http://terai.s55.xrea.com/swing/filteredtable/screenshot.png

class TestModel extends DefaultTableModel {



  private final Vector list = new Vector();
  public TestModel() {
    super(new String[]{NUMBER, MASTER, COMMENT}, 0);
  }
  public void addRow(Test tst) {
    list.add(tst);
    Integer num = new Integer(list.size());
    Object[] obj = {num, tst.getName(), tst.getComment()};
    addRow(obj);
  }
  public void filterRows(boolean flg) {
    Vector v = new Vector(list.size());
    for(int i=0;i<list.size();i++) {
      if(flg && !(i%2==0)) continue;
      Test t = (Test)list.elementAt(i);
      v.add(convertToVector(
        new Object[] {new Integer(i), t.getName(), t.getComment()}
      ));
    }
    setDataVector(v, columnIdentifiers);
    fireTableDataChanged();
  }
}