I have four columns of buttons in my program. Buttons move between columns when assigning new ones. Instead of declaring 4 separate arraylists to store the buttons, is there a way to create 1 arraylists array so that I can just iterate through the array?
I tried List<JButton>[] lists = new ArrayList<JButton>[5];
But that will not work. What am I missing?
EDIT:
for(int i = 0; i < 5; i++){ if(choiceList.getSelectedIndex() == i){ if(btnPersons[nameList.getSelectedIndex()].getX() == column[i]){ JOptionPane.showMessageDialog(null, "Error - Name already present in the column.","", 1); }else{ for(int j = 0; j < 5; j++){ if(lists[j].get(i) != null){ lists[j].remove(btnPersons[nameList.getSelectedIndex()]); } } lists[i].add(btnPersons[nameList.getSelectedIndex()]); lists[i].get(i).setBounds(column[i], ROWS[i], 125, 20);
This is my code now. When a new column is selected, it checks which row the button is in, and deletes it, and then adds it to the new list. But my new problem is that using lists [i] will no longer work. Idk, how to scroll my list of my arraists correctly using this ad:
List<ArrayList<JButton>> lists = new ArrayList<ArrayList<JButton>>();
mbreen
source share