Java Vector为什么只有第一个元素在表中显示

时间:2016-01-10 11:24:40

标签: java database swing vector jtable

package ferramenta.database.transaction.command;

import ferramenta.database.transaction.*;
import ferramenta.database.transaction.dao.*;
import javax.swing.table.DefaultTableModel;
import java.util.*;

/**
 * @author
 *
 */

public class RicercaProdotto implements Ricerca {

    private ProdottoDAO<Prodotto> prodotto = new ProdottoDAOImpl();
    private Vector<String>   myData  = new Vector<String>();
    protected Vector<String> vector1 = new Vector<String>();
    protected Vector<String> vector2 = new Vector<String>();

    @Override
    public void search(List<? extends Prodotto> lista, DefaultTableModel tableModel) {      
        for(Iterator<? extends Prodotto> it = lista.iterator(); it.hasNext();) {
            //Vector<String> myData    = new Vector<String>();
            Prodotto barcode = it.next();
            String valore = barcode.getBarcode();
            List<Prodotto> tmp = prodotto.selectProduct(valore);
            Prodotto p = tmp.get(0);
            System.out.println(myData.size());
            myData.add(p.getBarcode()); 
            myData.add(p.getModello());
            myData.add(p.getDescrizione()); 
            myData.add(Integer.toString(p.getQuantitativo())); 
            myData.add(Double.toString(p.getPrezzo()));
            System.out.println(myData.size());
            tableModel.addRow(myData);
        }
    }

}

通过这种方式,我得到了第一行重复的表

don't work table

如果我将Vector<String> myData = new Vector<String>();放在for循环中 有用 哪里有问题?我添加了2张图片

works table

0 个答案:

没有答案