Reputation: 1290
So to be specific i have a two-dimensional array filled with JLabels. If from another method i get one JLabel that we know for sure that exists in that array how can i get the coordinates of the label in the array. part of code is this(P.S The array is [9][5]):
labelsArrayColumns[1][1] = jLabel11;
labelsArrayColumns[2][1] = jLabel21;
labelsArrayColumns[3][1] = jLabel31;
labelsArrayColumns[4][1] = jLabel41;
labelsArrayColumns[5][1] = jLabel51;
labelsArrayColumns[6][1] = jLabel61;
labelsArrayColumns[7][1] = jLabel71;
labelsArrayColumns[8][1] = jLabel81;
labelsArrayColumns[9][1] = jLabel91;
So if I have jLabel81 how can i find out in which position of the array it is? And we are expecting [8][1].
Upvotes: 1
Views: 333
Reputation: 178
I'd suggest two ways:
1) work through the whole 2D-array and compare every element with labelsArrayColumns[i][j].equals(jLabel81)
until you find it
2) override the JLabel Class:
just add a method to save and retrieve the position of the JLabel within your array
Upvotes: 1