0
Person would like to know how to print an Arraylist inside a Jlabel, I am using Joptionpane but it shows one element at a time would like to show all the elements in a single window. Follow the code of the function that does this, how can I redo it ?
public void pesquisar(int i){
for(i=0 ; i < pessoas.size() ; i++){
JOptionPane.showMessageDialog(null,Pessoa.toString());
}
}
Take a look at this answer: https://answall.com/a/202836/28595
– user28595
This also solves your problem: https://answall.com/a/165733/28595
– user28595
This code has serious problems. First, the parameter
i
is not used for anything, since thefor
overwrites the value of this variable. Second, you iterate the list indexespessoas
, but inside the is, does not use neither the index nor the list for anything. Third thatPessoa.toString()
or will it always be the same person ifPessoa
is an instance variable (at odds with the standard variable nomenclature) or is a static method (which is probably bad programming practice). Room that in this code you don’t even try to use oneJLabel
.– Victor Stafusa