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.
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.
Therefore, I can only access the elements by
Component[] panels = frame.getContentPane().getComponents();
JPanel panel = (JPanel) panels[f];
Component[] components = panel.getComponents();
[...] determining the element class
JTextField field = (JTextField) components[u + 1]
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?