title: How do you create multiple JLabels with a while loop
body: <p>Okay I'm not really familiar with java, so the main deal here is that I'm trying to get contacts(friends if you'd like) from a database and listing them all as JLabels into a JPanel. I'm guessing this is a bad practice but I just want to try giving it a shot. </p>
  
  <pre><code>String query = "SELECT * FROM tblcontacts WHERE user_ID =\""+global.get_username()+"\"";
  //Just calling contacts from database with the account logged in
  JPanel contactlist = new JPanel();
  getContentPane().add(contactlist);
      try{
          Statement stmnt = conn.conn.createStatement();
          ResultSet rs = stmnt.executeQuery(query);
          while(rs.next()){
              //create JLabels here with the contact names and insert it into a JPanel
          }
      }catch(Exception e){
          System.out.println(e);
      }
  </code></pre>
  
  <p>Im quite stuck with it and I'm not sure how to add the labels in. Really sorry. </p>
  
  <p>*P.s. assume that the panels are working and everything has been set in a nice little window.</p>