Hi I am trying to access an array and show it in a dropdown list using joptionpane. I have it sort of working using:
for (int i = 0; i < data.length; r++)
{
Object list = JOptionPane.showInputDialog(null, "Select Code",
"Code", JOptionPane.QUESTION_MESSAGE, null, data[i][0], data[0][0]);
}
This brings up a dropdown list…but with only one piece of data and displays it about 5times (array length). How could I get this to display each data just in one dropdown?
Edit – Forgot to say when using data[i][0] it brings an error, as it only lets me use data[i] ? – “cannot find symbol”
Thanks
This is from the Java API:
Note that the selectionValues is a single dimensional array. When you feed in data[i][0], you are giving it a single value. When you feed in data[i] you are giving in a single row of the array, as a one dimensional array. (Recall that java doesn’t have n-Dimensional arrays, only arrays of arrays.)
You probably need to build a new one dimensional array, and feed that in.
Alternatively, if possible, convert the rows of your arrays to some object, and implement the toString() method in that class to display what you want.