Search code examples
javaarraylistjoptionpane

Showing Multiple Lines in a JOptionPane


So basically what I'm doing is get the all entries from an arraylist and show them in a JOptionPane window. But the problem is that a new JOPtionPane is opening everytime for every entry. Is there a way where I can list all entries in one JOptionPane ?? Thank you.

for ( int i = 0; i < LoansList.size(); i++)
{
    Loans myLoans = (Loans) LoansList.get(i);                     

    JOptionPane.showMessageDialog(null, myLoans.showDetails() + "\n ",
    "", JOptionPane.INFORMATION_MESSAGE); 
}

Solution

  • How about doing it like this:

    String acc = "";
    
    for (int i = 0; i < LoansList.size(); i++)
    {
        Loans myLoans = (Loans) LoansList.get(i); 
    
        acc += myLoans.showDetails () + "\n";
    }
    
    JOptionPane.showMessageDialog(null, acc, "", JOptionPane.INFORMATION_MESSAGE);