How do I list an Arraylist within a Jlabel

Asked

Viewed 231 times

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

  • This also solves your problem: https://answall.com/a/165733/28595

  • 2

    This code has serious problems. First, the parameter i is not used for anything, since the for overwrites the value of this variable. Second, you iterate the list indexes pessoas, but inside the is, does not use neither the index nor the list for anything. Third that Pessoa.toString() or will it always be the same person if Pessoa 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 one JLabel.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.