问题描述
- 我不知道如何在netbean中给表赋值!!求大神
-
public void QueryAll()
{
SAXReader reader=new SAXReader();
String classPath=ClassLoader.getSystemResource("").getPath();
System.out.println(classPath);
filename=classPath+"students.xml";
File file=new File(filename);
HashSet list=new HashSet();
try {
//reader.read(file);
document=reader.read(file);
} catch (DocumentException ex) {
Logger.getLogger(Help.class.getName()).log(Level.SEVERE, null, ex);
}
//获得根元素
Element root = document.getRootElement();
System.out.println(root.getName());
//迭代根元素root的子元素
List elementList = root.elements();
//System.out.println(elementList.size());
for(Element stuelem:elementList)
{
Student wqStudent=new Student();
Student.id= stuelem.attribute("id").getValue();
Student.name= stuelem.attributeValue("name");
Student.sex=stuelem.attributeValue("sex");
Student.age=stuelem.attributeValue("age");Student.account=stuelem.elementText("account");
Student.password=stuelem.elementText("password");
Student.email=stuelem.elementText("email");list.add(wqStudent);
}
System.out.println(list.size());
// Object[]data = list.toArray();
// String wqString="300";
// frame.getjTable1().setValueAt(wqString, 1, 1);
// System.out.println(frame.getjTable1().getValueAt(1, 1));
// System.out.println("22222222222");// String[] columnNames = {"Product","Number of Boxes","Price"};
TableModel model=frame.getjTable1().getModel(); //this.TableInfo.
for(int i=0;i<list.size();i++){
model.setValueAt(str[i+1][1],i,0);
model.setValueAt(str[i+1][2],i,1);
model.setValueAt(str[i+1][3]+str[i+1][4],i,2);
model.setValueAt(str[i+1][5],i,3);
model.setValueAt(str[i+1][6],i,4);
model.setValueAt(str[i+1][7],i,5);
model.setValueAt(str[i+1][8],i,6);
model.setValueAt(str[i+1][9],i,7);
model.setValueAt(str[i+1][10],i,8);
model.setValueAt(str[i+1][11],i,9);
model.setValueAt(str[i+1][12],i,10);
model.setValueAt(str[i+1][13],i,11);
model.setValueAt(str[i+1][14],i,12);
}
}