title: Java Assigning Value to ComboBox
body: <pre><code>public static JComboBox[] ComboBox = new JComboBox[100];    
  String Array[] = { "Item1", "Item2", "Item3", "Item4" };
  
  final DefaultComboBoxModel model = new DefaultComboBoxModel(Array); // this should assign the array and it does
  ComboBox[1] = new JComboBox(model); // added this as the above also didn't help
  ComboBox[1].setModel(model); // added this in because the above line didn't help
  </code></pre>
  
  <p>The issue I'm having with this code is its returning as part of the values, "[L]java,labg.String.....".  I think this relates to the fact the array has been called (as a string not a true array).</p>
  
  <p>I've tried every possible method i can think of to get rid of that random entry, I've tried true arrays, lists, nothing works. If I delete out Array..</p>
  
  <pre><code>ComboBox[1] = new JComboBox();
  </code></pre>
  
  <p>and just call the ComboBox naturally, its still there and I can't figure out why.</p>
  
  <p>Updated 18/09/17 @ 7.17am</p>
  
  <p>Sorry I didn't really ask the question too well, it was really late and I'm actually experienced in VBA not so much in Java (which i'm still learning forgive me).</p>
  
  <p>Yes I would like to improve my syntax approach, so please feel free to review my code.</p>
  
  <p>Okay to start with, here is the design of the program. The purpose of the application is assist with capturing data in different aspects of their job, as they have templates they must fill out each time they preform an action (like changes address, leaves the country etc).</p>
  
  <p>They select the questionset (example change of address), and then the template they need to fill out populates onto the userform.</p>
  
  <p>The issue I was having was that when adding a dynamic combobox as an array, the combobox was displaying a strange item ([L]java,labg.String.....), even when all elements of the combobox are empty (or forced to be empty).</p>
  
  <p>All I want is to be able to generate a dynamic combobox in an array format, and be able to retrieve the value the user has selected.</p>
  
  <p>In writing the test code for you guys that you can compile....it just works fine...so I'm thinking I need to re-evaluate how the rest of my program is designed.</p>
  
  <p>Here is the code for your reference, if you could help me figure out how to pass non static method's I'd appreciate that too!</p>
  
  <pre><code>import javax.swing.JButton;
  import javax.swing.JFrame;
  import java.awt.event.*;
  import java.awt.BorderLayout;
  import javax.swing.JComponent;
  import javax.swing.JOptionPane;
  import javax.swing.JSplitPane;
  import java.awt.event.ActionEvent;
  import java.util.ArrayList;
  import javax.swing.JButton;
  import javax.swing.JCheckBox;
  import javax.swing.JComboBox;
  import javax.swing.JComponent;
  import javax.swing.JLabel;
  import javax.swing.JTextField;
  import java.util.List;
  import javax.swing.DefaultComboBoxModel;
  
  
  public class ExampleApplication {
  
  public static JComboBox[] my_dynamic_combobox = new JComboBox[100];    // Declare my dyanmic combobox so its visible throughout the instance of this class (see my explanation as to why I use static objects)
  public static JFrame userform1 = new JFrame("My UserForm"); // Creates new instance of JFrame with title 'My UserForm'
  public static class my_functions {   // This is what I use to hold my functions to avoid repitition in code
  
      public static void add_dynamic_combobox(int my_combobox_array, String[] my_combobox_items) {     // This is a function, it adds a new dynamic combobox based on the value passed form a loop, and assigns the relevant list to it.
          my_dynamic_combobox[my_combobox_array] = new JComboBox(my_combobox_items);      // This should populate the newly created combobox, with its relevant items ONLY
          my_dynamic_combobox[my_combobox_array].setBounds(10, 10, 100, 20); // I'm only displaying one combobox at the moment, so positioning doesn't matter here.
          userform1.add(my_dynamic_combobox[my_combobox_array]);
      }
      // End of my_functions class
  }
  
  
  public static void main(String[] args) {
      // The static void won't let me pass in/out any arguments or run any class/methods that aren't static. I don't know how to get around this. Doesn't like non-static context
      String the_list[] = { "Item1", "Item2", "Item3"};
  
      userform1.setSize(900, 225);    // Set 400 width and 500 height
      userform1.setLayout(null);  // Using no layout managers
      userform1.setDefaultCloseOperation(userform1.EXIT_ON_CLOSE);    // define exit behaviour
  
      for (int i=0; i&lt;10; i++){
          my_functions.add_dynamic_combobox(i, the_list);
      }
  
      // Loop has finished display the form.
      userform1.setVisible(true);
  
  
  }
      }
  </code></pre>
  
  <p>edit 2: 18/09/17 @ 9.39pm - Still no luck is isolating the code that is causing the issue. It definitely seems to be an issue when referring between static and non-static methods though.</p>