java - Reference to row in JTable -
jtable stores rows can added, deleted, shuffled, dynamically. in implementation row represent download, progress can dynamically updated, passing value of 1 of unique attribute called id. how map id actual row?
iterating on column not efficient approach. there way dynamically synchronize hashmap<id,object[]> jtable, such given key can update corresponding row, , vice versa?
private dfttasks=new defaulttablemodel(); public void addtask(string type, string name, int progress, int sessionid) { object[] rowdata={type,name,new integer(progress),new integer(sessionid)}; dfttasks.addrow(rowdata); } public void updateprogress(int sessionid, int progress) { int = dfttasks.getrow(sessionid); //<--alternative method dfttasks.setvalueat(new integer(progress), i, 2); //2nd column=progress }
- create class encapsulate data (eg
type,name,progress, ,id). - store instance of (1) in
list, , if necessary other data structure quick access (egmapkeyed id). order oflistrow order of table. - extend
abstracttablemodel, , implement necessary methods return valueslist(1) , (2) based upon row/column. - when values of instances (2) changed (eg, progress updated), call firexxx within implementation in (3) (the source of
defaulttablemodelexample of how done)
Comments
Post a Comment