title: How to access elements in a JPanel that I don't have stored as a variable? Java/Swing
body: <p>I'm building a classic form GUI with a variable amount and order of JTextFields, JCheckBoxes and JComboBoxes, with separate JPanels containing several groups of them.</p>
  
  <p>For now I just build them in a builder method that adds a JLabel + the appropriate input Element to a JPanel and returns the JPanel to the main initialize method.</p>
  
  <p>Therefore, I can only access the elements by  </p>
  
  <pre><code>Component[] panels = frame.getContentPane().getComponents();  
  JPanel panel = (JPanel) panels[f];  
  Component[] components = panel.getComponents();  
  
  [...] determining the element class  
  JTextField field = (JTextField) components[u + 1]
  </code></pre>
  
  <p>Reading works fine with this method, but setting values is harder because I'm currently not accessing the elements directly. Am I doing something wrong or do I have to rebuild the panel from the start?  </p>