title: Displaying an ArrayList in a Panel
body: <p>I am having this problem in below code as my ArrayList both name and values I wish to be displayed on the window is not appearing. It should be displayed at the bottom of the window but I set everything possible to setVisible true but still unable to display it. I think its a minor mistake but I cant see as it is my code. Sorry that the code is such a mess as I am writing this for my own understanding.</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.util.*;
  import javax.swing.*;
  
  
  public class SamplePaper5a {
  
      static final int width = 500;
      static final int hight = 600;
  
      /**
       * @param args
       */
      public static void main(String[] args) {
          // TODO Auto-generated method stub
  
          JFrame frame = new JFrame("Exam");
          frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
          frame.setSize(width,hight);
          Container contain = new Container();
          contain = frame.getContentPane();
  
          contain.setLayout(new GridLayout(2,2));
  
          final ArrayList&lt;String&gt;names = new ArrayList&lt;String&gt;();
          final ArrayList&lt;String&gt;values = new ArrayList&lt;String&gt;();
  
          names.add("dian");
          names.add("maze");
          names.add("carl");
          names.add("John");
          names.add("tan");
          names.add("james");
  
          values.add("11111");
          values.add("2222");
          values.add("3333");
          values.add("4444");
          values.add("5555");
          values.add("6666");
  
          final JTextArea txtArea = new JTextArea();
          JButton butt = new JButton(" Enter ");
          contain.add(txtArea);
          contain.add(butt);
  
          butt.addActionListener(new ActionListener()
          {
  
              @Override
              public void actionPerformed(ActionEvent e) {
                  // TODO Auto-generated method stub                                  
                  for(int i=0;i&lt;values.size();i++)
                  {
                      txtArea.setText( txtArea.getText()+" \n "+values.get(i) +"  "+ names.get(i));                       
                  }
              }               
          });
  
          try
          {
              contain.add(new NamePanel2(names,values,1));
  
          }
  
          catch(Size2Exception e)
          {
              System.out.print(e);
          }
  
          frame.setVisible(true);
      }   
  }
  
  class NamePanel2 extends JPanel 
  {
      ArrayList&lt;String&gt; names = new ArrayList&lt;String&gt;();
      ArrayList&lt;String&gt; values = new ArrayList&lt;String&gt;();
      int cols;
  
      public NamePanel2(ArrayList&lt;String&gt; nam,ArrayList&lt;String&gt; val,int c) throws Size2Exception
      { 
          this.names = nam;
          this.values =val;
          this.cols = c;
          JPanel panel = new JPanel();
  
          if(names.size()!= values.size())
              throw new Size2Exception(" wrong sizes");
  
          panel.setLayout(new GridLayout(names.size(),cols));
  
          for(int i = 0; i&lt;names.size();i++)
          {
              panel.add(new JLabel(names.get(i)));
              panel.add(new JTextField(values.get(i)));
          }
          panel.setVisible(true); 
      }       
  }
  
  class Size2Exception extends Exception
  {
      public Size2Exception(String str)
      {
          super(str);
      }
  }
  </code></pre>