Good evening stack overflow ... I write to you because I have a problem, which, until now I have not been able to solve, I already have 2 days writing and erasing code ... The problem consists of:
I create a small graphical interface, to be more exact, a form in swing, then, the form consists of: Name, ID, Address, gener and hobbies. Then, I collect these data with an ACTIONLISTENER in a JBUTTON, and ok, I collect the data and keep it in the respective ARRAYLIST. Note that, I create an object every time I fill the form, therefore, I can add N number of people ... Well the problem is that, create a class where I create my JTABLE, and I want to pass the data of the arraylist to the table. The code I have is:
public class TablaPanel extends JPanel{
DefaultTableModel modelotabla;
JTable tabla1;
JScrollPane scroll1;
Object columnas[] = {"NOMBRES","CEDULA","DIRECCION","SEXO (M/F)","HOBBIES"};
Object[] fila = new Object[contador.contadorfilas];
Persona pnew = new Persona(); //esta es la clase que tiene las variables de persona
FormularioCapa contador = new FormularioCapa(); //para poder obtener contador de cada vez que se presiona
//el jbutton
public TablaPanel(){
modelotabla = new DefaultTableModel(columnas,0); //0 son las filas
tabla1=new JTable(modelotabla);
add(tabla1);
ArrayList<Persona> list = lista.getListaDePersonas();
for(int i=0;i<contador.contadorlista;i++){
fila[i]=pnew.getName1();
fila[i]=pnew.getCedula();
fila[i]=pnew.getAddress();
fila[i]=pnew.getGender();
modelotabla.addRow(fila);
}
//CONTADORLISTA es para agregar n Filas, y esa n lo define un contador que va sumando 1, cada vez que
//se agrega una nueva persona (o sea, cada vez que se presiona el jbutton)
scroll1 = new JScrollPane(tabla1);
add(scroll1);
}
The problem is that, it does NOT show me the text in the cells of the JTABLE. But if you take into account the counter. That is, if I add 5 people, I take into account the 5 rows and add them, but NOT the data of the rows, just add the empty rows without any information ...
It should be noted that I have a System.out.println, which shows me the complete arraylist once the n people are added, and if they are saved (n number of people with their data that are added through the graphical interface). The thing is that, it does not show them (the people added and their information) in the cells of the JTable ...
It's my first time working with JTABLE, I hope you understand. Greetings and happy night