二维数组如何删除事特定行的数据

sailland 2012-06-12 07:25:02
从一个JTABLE MODEL中返回的数组,我想删除页数为零的数据,然后PUT到MAP里面,请教高手应该怎么删除?

model里面的数据
        private String[] columnNames = {"名称", "页数"};
private Object[][] data = {
{"KathySmithSnowboarding", new Integer(5)},
{"DoGFGFhnDoeRowing", new Integer(0)},
{"TUHJohnDoeRowing", new Integer(7)},
{"OPKJJohnDoeRowing", new Integer(0)},}



未完成的代码
 private void TranceData() {

int RowsCount = 0, numRows = tb.getRowCount(),numCols=tb.getColumnCount();
Object tmp[][] = new Object[numRows][numCols];

for (int i = 0; i < numRows; i++) {
for (int j = 0; j < numCols; j++) {
tmp[i][j] = tb.getValueAt(i, j);
System.out.print("|"+tmp[i][j]);
}
}

for (int i = 0; i < numRows; i++) {

if (tb.getValueAt(i, 1) != "0") {
RowsCount++;

}

}

Object[] objs = new Object[RowsCount];
for (int j = 0; j < RowsCount; j++) {

Map maps = new HashMap();
maps.put("内容", );
maps.put("页数", );
objs[j] = maps;
}

...全文
176 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
sailland 2012-06-12
  • 打赏
  • 举报
回复
终于搞定了,用了最笨的数组复制办法,下次一定要建个LIST模型啊



private void TranceData() throws JRException {
JasperReport jasperReport;
JasperPrint jasperPrint;



int RowsCount = 0, numRows = tb.getRowCount(),numCols=tb.getColumnCount();
Object tmp[][] = new Object[numRows][numCols];

for (int i = 0; i < numRows; i++) {
for (int j = 0; j < numCols; j++) {
tmp[i][j] = tb.getValueAt(i, j);
//System.out.print("");//("|"+tmp[i][j]);
}
}

//System.out.print(tmp.getClass());




for (int i = 0; i < numRows; i++) {

if (tb.getValueAt(i, 1) != "0") {
RowsCount++;
}
}
//System.out.println(RowsCount+""+tb.getValueAt(1, 1).getClass());
Object forMap[][]=new Object[numRows][numCols];

int ci=0,cj=0;
while(cj<RowsCount)
{

if (tmp[ci][1]!="0"){
forMap[cj][0]=tmp[ci][0];
forMap[cj][1]=tmp[ci][1];
cj++;
}

ci++;
}

//debug
if(false){
// System.out.println(forMap.length);
for (int i = 0; i <RowsCount; i++) {
for (int j = 0; j < numCols; j++) {
System.out.print("fromat|"+forMap[i][j]+"|");
}
}

}



////
// int hi=0;
// while (tmp[hi][1]=="0"){
// for(int i=hi-1;i<tmp.length;i++){
//tmp[i][0]=tmp[i+1][0];
//tmp[i][1]=tmp[i+1][1];
//
// }
// //tmp--;
// }




Object[] objs = new Object[RowsCount];


for (int j = 0; j < RowsCount; j++) {

Map maps = new HashMap();
maps.put("name", forMap[j][0]);
maps.put("address", forMap[j][1]);
objs[j] = maps;
}

JRDataSource dataSource = new JRMapArrayDataSource(objs) {};
jasperReport = JasperCompileManager.compileReport("./reports/report1.jrxml");
jasperPrint = JasperFillManager.fillReport(jasperReport, null, dataSource);
//JasperExportManager.exportReportToPdfFile(jasperPrint, "c://1.pdf");
JasperViewer.viewReport(jasperPrint);
sailland 2012-06-12
  • 打赏
  • 举报
回复
这个JTABLE是一直要用的,不能删,只能对返回的数组进行操作
jlu_lamp_lamp 2012-06-12
  • 打赏
  • 举报
回复
返回数组里?
可以用JTable里面的deleteRow的方法删除啊
然后就注意操作的时候剔除已经被删掉的数据就行了

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧