java - How do I properly use an array with JComboBox? -


I am running with my code in some code which is about implementing an ArrayList in JComboBox. I'm able to do this by using code like "codeList.addItem (selectItem)" code; without an array The one I am trying to accomplish is to use a new list to send new information in the second part of the GII so that I use that array to save and load data while the user starts a GUI. Can do Question: How do I use an array with JComboBox? I have seen some tutorials, but I do not think get the combobox to update with elements in the array. I am making a mistake somewhere, if you can help, I would be really grateful.)

// This piece of code is the main Java file; Order is in OrderSystem.java.

  order system order = new order system (); Outerst & lieutenant; String & gt; List = order.getArrayList ();   

// Retrieves the selected data from JComboBox (one from a separate) and adds it to the array list.

  JComboBox & lt; String & gt; Test = room.getRoomType (); String selected item = (string) Test.getSelectedItem (); List.add (sealed ctedItem);   

Now, inside OrderSystem.Java: creates an ArrayList and JComboBox

  ArrayList < String & gt; List = New Arrestist & lt; String & gt; (); JComboBox & LT; Object & gt; RoomList; ... setComboBox (new JComboBox & lt;> (list.toArray ()));   

// Sets and Gates

  Public array list & lt; String & gt; GetArrayList () {Return List; } Public Zero SetArealist (Arlist & Lt; String & gt; List) {this.list = list; }   

Thanks! Try it:

  comboBox.setModel (New DefaultComboBoxModel &  & gt; (list.toArray (new string [list.size ()])));    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -