I would like to display a list of arrays stored in my main class in a JFrame contentpane created in another class. I think I have the basics of how to create a JFrame and contentpane however im not clear as to how to pass the array into the JFrame, so that when i run the program the list of arrays displays on the window. Any insight will be much appreciated I'm new to Java
You can't exactly "display" a stand-alone array.
There are a couple of ways you could go about doing this.
I'm going to show you how to use a JList with a Default List Model and populate it with content from an array.
First, Create a new DLM and JList as well as a JScrollPane and bind the DLM to the JList and the JList to the JScrollPane to display the content properly if there is more items in the array then can be shown:
DefaultListModel dlm = new DefaultListModel();
JList list = new JList(dlm);
JScrollPane scrollPane = new JScrollPane(list);
Next, take you're array and add the items to the DLM
String[] content = {"Some", "Random", "Words"};
for(String word : content)
{
dlm.addElement(word);
}
You now have a JList with the content of the Array, all you have to do is add the JScrollPane
to the JFrame
someFrame.add(scrollPane);