I am writing a program that reads a file into an arrayList. The first value of the file is a description which I pull out and popualte a ComboBox with. I need to be able to make a selection from the combobox and have the entire object then be displayed in a textarea.
My first thought was to add a button to the right of the combobox that would get which line was selected then pull the approprate object from the arraylist and add it to the textarea. I just can seem to get it to work.
Here is the code for the comboBox
BufferedReader in = new BufferedReader(new FileReader("FoodCalories.txt"));
while ((s = in.readLine()) != null)
StringTokenizer st = new StringTokenizer(s, "*");
// Fill an Array with Food Objects read from file
Food food = new Food(st.nextToken(), st.nextToken(), Integer.parseInt(st.nextToken()));
catch (IOException ex)
// Create Combo Box
JComboBox comboBox = new JComboBox();
// Populate ComboBox with just Food Description
for( int i=0; i<foods.size(); i++ )
Food foodFromArrayList = (Food)foods.get(i);
comboPanel.add ( comboBox );