java Swing填充数据到table中去,第一次点击数据出来,第二次在点击table会追加记录
privateAdvertDaoadvertDao=newAdvertDaoImpl();privateDefaultTableModeldtm=null;String[...
private AdvertDao advertDao = new AdvertDaoImpl();
private DefaultTableModel dtm = null;
String[] tableHeads = null;
/**
* table展示
*/
public void showTable() {
tableHeads = new String[] { "ID", "名字" };
dtm = (DefaultTableModel) jTable1.getModel();//创建model
dtm.setColumnIdentifiers(tableHeads);//创建表头,表头的类型可以是vector 或者Object[]
}
/**
* 点击查询填充table
* @param evt
*/
private void QueryButtonActionPerformed(java.awt.event.ActionEvent evt) {
showTable();
List<Advert> list = advertDao.QueryAdvert();
Vector v1 = null;
for (Advert advert : list) {
v1 = new Vector();
v1.add(advert.getId());
v1.add(advert.getLedName());
dtm.addRow(v1);//添加行数据,类型可以是vector 或者 object[];
}
} 展开
private DefaultTableModel dtm = null;
String[] tableHeads = null;
/**
* table展示
*/
public void showTable() {
tableHeads = new String[] { "ID", "名字" };
dtm = (DefaultTableModel) jTable1.getModel();//创建model
dtm.setColumnIdentifiers(tableHeads);//创建表头,表头的类型可以是vector 或者Object[]
}
/**
* 点击查询填充table
* @param evt
*/
private void QueryButtonActionPerformed(java.awt.event.ActionEvent evt) {
showTable();
List<Advert> list = advertDao.QueryAdvert();
Vector v1 = null;
for (Advert advert : list) {
v1 = new Vector();
v1.add(advert.getId());
v1.add(advert.getLedName());
dtm.addRow(v1);//添加行数据,类型可以是vector 或者 object[];
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询