0

I just found this problem when I want to full my JTable I have this method that return an arrayList of categories :

public static ArrayList<Categorie> findAll() {
    ArrayList<Categorie> list  = new ArrayList<Categorie>();
    try {

        Statement st = connect.createStatement();
        String sql = "select * from categorie ";
        ResultSet rs = st.executeQuery(sql);
        while (rs.next()){
            Categorie tmp = new Categorie(rs.getInt("idcategorie"),rs.getString("description"));
            list.add(tmp);
        }



    } catch (SQLException e) {
            e.printStackTrace();
    }
    return list;

}

and here is the categorie class (POJO) :

    package modele;

public class Categorie {
private int idcategorie;
private String description;
public Categorie(){

}
public Categorie(int idcategorie, String description) { 
    this.idcategorie = idcategorie;
    this.description = description;
}
public int getIdcategorie() {
    return idcategorie;
}
public void setIdcategorie(int idcategorie) {
    this.idcategorie = idcategorie;
}
public String getDescription() {
    return description;
}
public void setDescription(String description) {
    this.description = description;
}
@Override
public String toString() {
    return "Categorie [idcategorie=" + idcategorie + ", description="
            + description + "]";
}

}

so, I want to full my JTable with this arrayList but the constructor doesn't accept

arrayList<Categorie>

and I tested also :

ArrayList<Contact> listc = ContactDAO.findAll();    
Contact[] cs = listc.toArray(new Contact[listc.size()]);
        JTable t = new JTable(cs, columnNames);

but it doesn't accept cs field

do you have any idea

thank you in advance

simonTifo
  • 307
  • 3
  • 12
  • 29
  • 1
    this and similair issues were solved by implements `AbstractTableModel`, more see in `Oracle Tutorial`, bunch of code examples on this forum, have to decide for `proper array type`, this question in this form isn't answerable, maybe shot from the dark can answering your question without posting an [SSCCE](http://sscce.org/), short, runnable, compilable, just about `JFrame`, `JTable`, `XxxTableModel` and with hardcoded value stored as `local variable` – mKorbel Jan 08 '13 at 11:16
  • 1
    For [example](http://stackoverflow.com/a/9134371/230513). – trashgod Jan 08 '13 at 11:26

0 Answers0