JTable and JavaBeans
Hello everybody.
I'm trying to build dinamically a JTable, reading data from a JavaBean.
Everythings works fine, but :
1) if I click outside of my JFrame, when I reselect it the JTableis completely filled with the last row inserted
2)If I scroll the JTable (that is contained in a JScrollPane), rows that momentanely disappear because of the scroll, when I rescroll to the original position I discover that all rows that were "out of sight" as been filled up ith last row's data
3)If I select a column, a row, or simply a cell, when I click on another one this another one's row is filled up with last row data
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.table.AbstractTableModel;
import beans.ArticoloBean;
class TableModelextends AbstractTableModel{
private String colonna1;
private String colonna2;
private ArrayList list;
private String[] Columns ={
"Articolo","n癱olli","Note"
};
Iterator Ilista_articoli;
ArticoloBean myBean = (ArticoloBean)Ilista_articoli;
int rowcount=0;
public TableModel(ArrayList list){
this.list=list;
Ilista_articoli=list.iterator();
if (Ilista_articoli.hasNext()){
myBean = (ArticoloBean)Ilista_articoli.next();
}
}
publicint getRowCount(){
return list.size();
}
publicint getColumnCount(){
return Columns.length;
}
public Object getValueAt(int riga,int colonna){
if (rowcount==3){
if (Ilista_articoli.hasNext()){
myBean = (ArticoloBean)Ilista_articoli.next();
rowcount=0;
}
}
rowcount++;
if (colonna==0)return myBean.getCodice();
if (colonna==1)return myBean.getColli();
if (colonna==2)return myBean.getNote();
returnnull;
}
publicboolean isCellEditable(int riga,int colonna){
returnfalse;
}
public String getColumnName(int colonna){
return Columns[colonna];
}

