java - Set XML values in jTable -
i've got jtable , want add content of xml-file it. dont know how should browse through xml-file, able manipulate data (rewrite, deleting) , values of single tag , not of all. i'm using jdom
my xml-file looks this:
<?xml version="1.0" encoding="utf-8"?> <app> <!-- pfad für templates und speicher ort für die entity.java--> <entity> <name>aposting</name> <art>0</art> <datum>wed nov 19 10:51:10 cet 2014</datum> </entity> <entity> <name>aposting</name> <art>1</art> <datum>wed nov 19 11:30:34 cet 2014</datum> </entity> <entity> <name>aposting</name> <art>1</art> <datum>wed nov 19 15:21:12 cet 2014</datum> </entity> <entity> <name>aposting</name> <art>2</art> <datum>thu nov 20 8:01:10 cet 2014</datum> </entity> </app>
and want display in table this:
thank help
edit:
i've made custom model
package tabletest; import java.util.arraylist; import java.util.date; import java.util.list; import javax.swing.event.tablemodellistener; import javax.swing.table.tablemodel; /** * * @author administrator */ public class modeldata implements tablemodel { list<tabledata> data = new arraylist<>(); string colnames[] = {"name", "type", "date"}; class<?> colclasses[] = {string.class, string.class, date.class}; modeldata() { data.add(new tabledata("aposting", "created", new date())); data.add(new tabledata("aposting", "edited", new date())); data.add(new tabledata("aposting", "edited", new date())); data.add(new tabledata("aposting", "deleted", new date())); } @override public int getrowcount() { return data.size(); } @override public int getcolumncount() { return colnames.length; } @override public object getvalueat(int rowindex, int columnindex) { if (columnindex == 0) { return data.get(rowindex).getname(); } if (columnindex == 1) { return data.get(rowindex).gettype(); } if (columnindex == 2) { return data.get(rowindex).getdate(); } return null; } @override public string getcolumnname(int columnindex) { return colnames[columnindex]; } @override public class<?> getcolumnclass(int columnindex) { return colclasses[columnindex]; } @override public boolean iscelleditable(int rowindex, int columnindex) { return true; } @override public void setvalueat(object avalue, int rowindex, int columnindex) { if (columnindex == 0) { data.get(rowindex).setname((string) avalue); } if (columnindex == 1) { data.get(rowindex).settype((string) avalue); } if (columnindex == 2) { data.get(rowindex).setdate((date) avalue); } } @override public void addtablemodellistener(tablemodellistener l) { } @override public void removetablemodellistener(tablemodellistener l) { } }
and tabledata class access:
package tabletest; import java.util.date; public class tabledata { string name; string type; date date; public tabledata(string name, string type, date date) { super(); this.name = name; this.type = type; this.date = date; } public string getname() { return name; } public void setname(string name) { this.name = name; } public string gettype() { return type; } public void settype(string type) { this.type = type; } public date getdate() { return date; } public void setdate(date date) { this.date = date; } }
and works added values in "modeldata" still got no clue how extract entities out of xml-file
you'll need 2 things this:
a suitable xml parser.
a custom table model, illustrated here.
depending on chosen parser, can either
construct java data structure, e.g.
list<entity>
, can accessed intablemodel
.access document object model directly meet
tablemodel
contractgetvalueat()
,getrowcount()
, etc.
addendum: based on edit,
Comments
Post a Comment