java - sort JTable's entries without clicking on column header -
java - sort JTable's entries without clicking on column header -
i've implemented row sorting on jtable both using defaultrowsorter , custom defined row sorter class. works fine clicking on column header sort table.
but if want invoke sort operation within application code ( without clicking on column header). method have phone call ?
edit:
i initialize tables row sorter way:
public void buildrowsorter() { tablerowsorter<mymodel> sorter = new tablerowsorter<mymodel>((mymodel)this.table.getmodel()); seek { sorter.setcomparator(0, new mycustomcomparator<double>(sorter,0)); sorter.setcomparator(1, new mycustomcomparator<string>(sorter,1)); } grab (parseexception e) { e.printstacktrace(); } this.table.setrowsorter(sorter); } now like, having reference jtable (table), retrieve associated row sorter particular column of model, , invoke sort operation on it.
as far can see have custom comparator (why maintain reference sorter? looks fishy) not custom rowsorter.
the intended way alter sorting invoke togglesortorder(column) on rowsorter. more fine-grained command can need access defaultrowsorter, f.i. setsortkeys method.
java swing sorting jtable
Comments
Post a Comment