I'm working on a project for work involving a JTable with a dynamic number of columns. Each column is basically a separate transaction but I do not know the number of transactions a file will have ahead of time.
Typically when I create a JTable I know how many columns I will have and I declare it like this:
String header[] = new String[]{
"Tag","Transaction1"
};
For this project however there can be any number of transactions each time the program is used so I would need to dynamically add columns based upon the length of a certain array before I even create my rows. (The first row is actually going to also be used as a header).
So I have an array with a given length, but I don't know how to use this value in a loop, at least not with creating an object like the code above shows.
For example let's say the user uploads a file that has 3 transactions.. I would need my String header[] to read:
String header[] = new String[]{
"Tag","Transaction1","Transaction2","Transaction3"
};
I'd considered possibly creating an array list and adding the transactions to this using a counter and a loop, then possibly extracting the values into the String[] header although I'm not sure if this is the best approach and even still how exactly to make it work.