-1

Click here for the unfinished project.I am trying to make a program in which its a shop, and the admin account and remove and add items (which is why i have used an arraylist). I have managed to make the arraylist and i think i have done it right. I want to make it two dimensional as when you click on the item it tells you information related to it aswell. Is there some way of doing it thats different to mine and would be easier to code? Also, i am trying to use this arraylist in a jcombobox but what im doing is putting it all into one line. I have tried for loops with no luck. Any suggestions?

public class Main {


public static Login form = new Login();
public static ArrayList<ArrayList<String>> instt = new ArrayList<ArrayList<String>>();
  public static  ArrayList<String> row = new ArrayList<String>();

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {


    row.add("Chelo");
    row.add("Drums");
    row.add("Flute");
    row.add("Guitar");
    row.add("Harp");
    row.add("Piano");
    row.add("Recorder");
    row.add("Trombone");
    row.add("Trumpet");
    row.add("Xylophone");
    instt.add(row);


    form.setVisible(true);
}

Here is the other class (GUI)

private void load_custActionPerformed(java.awt.event.ActionEvent evt) {                                          
    load_cust.setVisible(false);
    test.addItem(Main.instt);

There are other classes aswell but i think they are unrelated to the question i am asking but they available on request.

4
  • can you please display other part of code which is related to this code ? if you can please. bcz i am unable to clearly undertand your requirement. Nov 27, 2015 at 19:22
  • 1
    Your question is a bit confusing. Could you clarify and post a Runnable example instead of just a part of it?. I have tried for loops with no luck (no luck, what was the result?)
    – Frakcool
    Nov 27, 2015 at 19:23
  • I have added a link to my project, click on "Im a customer, and when i press load, thats when the issue arises. the reason i put the load button is because i dont know how to make things load when the jframe opens. Thank you
    – Dullah
    Nov 27, 2015 at 19:40
  • @Dullah You must bring the relevant code here. We are here to help YOU, so we should not have to jump through obstacles to provide that help. Everything we need should be put into your question (code, images, ect...). Also, only include the code thats directly related to the problem, not your entire project.
    – Vince
    Nov 27, 2015 at 20:28

1 Answer 1

1

The easiest way I can think of off hand to dump your current ArrayList into your JComboBox is to use a simple "for loop":

for (int i = 0; i < row.size(); i++) {
    yourComboBox.addItem(row.get(i));
}

This should get you started...

1
  • Yes, that was a great starter, I manged to get what i wanted in the end.
    – Dullah
    Nov 27, 2015 at 21:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.