title: Java ComboBox Association with arraylist
body: <p>Please help me on the following code guys, I am trying to return arraylist elements(searched ports) from a method in class <code>SearchPort</code>. This would then be used in the corresponding class Communication, where the method <code>returnArray()</code> would be called to extract strings to be used for <code>Jcombox</code> options. But how do I go about doing it?  Please help. </p>
  
  <pre><code>public class SearchPort {
  
      CommPortIdentifier portIdentifier;
  
      ArrayList &lt;String&gt; portFound ;
  
      public void listPorts() {
          portFound = new ArrayList();
          //Enumeration holds all port objects
          Enumeration&lt;CommPortIdentifier&gt; portEnum = CommPortIdentifier.getPortIdentifiers();
          while ( portEnum.hasMoreElements() ) //while Enumeration contains more port objects 
          {
              portIdentifier = portEnum.nextElement(); //switches through each port
              portFound.add(portIdentifier.getName());           
          } 
       }
  
       public String returnArray(){
  
            listPorts();
            for(int i = 0; i &lt; portFound.size(); i++){
                System.out.println(portFound.get(i));
  
            }
            return portFound;
        }    
  
    public static void main(String[] args){
        SearchPort run = new SearchPort();
        run.listPorts();
    }
  
  }
  
  public class Communication {
  
  JLabel jLabel1;
  JPanel jPanel1;
      JComboBox Connections;
  
      public Communication() {
          JFrame commFrame = new JFrame("gec");
          commFrame.pack();
          commFrame.setVisible(true);
          commFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      commFrame.setSize(300,300); 
  
      jLabel1 = new JLabel();
      jPanel1 = new JPanel();
  
      jLabel1.setText("GEC");
          Font font = new Font("Calibri", Font.BOLD, 14);
          SearchPort port = new SearchPort();
          String [] portStrings = { port.returnArray()}; //add found ports into array
          Connections = new JComboBox(portStrings); 
          Connections.addItemListener(null);
      jLabel1.setFont(font);
      jPanel1.add(jLabel1, BorderLayout.EAST);
          jPanel1.add(Connections, BorderLayout.CENTER);        
         /*Add Contents to the Frame*/ 
          commFrame.add(jPanel1); 
      }
  
      public static void main(String args[]) {       
          Communication GUI = new Communication();            
      }
  
  }//end class
  </code></pre>