1

So I think you will understand my problem by this piece of code:

int s = 4;
int v = 4;    

world.setLayout(new GridLayout(s, v));

        grid = new JLabel[s][v];

        for (int x = s-1; x >= 0; x--) {

            for (int y = 0; y < v; y++) {

                grid[x][y] = new JLabel((x)+","+(y));

                world.add(grid[x][y]);

Now I get a grid with coordinates:

3,0  3,1  3,2  3,3
2,0  2,1  2,2  2,3
1,0  1,1  1,2  1,3
0,0  0,1  0,2  0,3

But I would like to get:

0,3  1,3  2,3  3,3
0,2  1,2  2,2  3,2
0,1  1,1  2,1  3,1
0,0  1,0  2,0  3,0

Any help appreciated..

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
DJack
  • 631
  • 1
  • 8
  • 34
  • Maybe you should be clear about how are you representing you grid. It looks like you want to specify x and y coordinates, but what you showed could be rows and columns. – cangrejo Nov 29 '13 at 12:50
  • You might get some ideas form this Q&A: [How to get X and Y index of element inside GridLayout?](http://stackoverflow.com/questions/7702697/how-to-get-x-and-y-index-of-element-inside-gridlayout) – trashgod Nov 29 '13 at 15:13

2 Answers2

0

I didn't test it but try this out:

    for (int y = s-1; y >= 0; y--) {

        for (int x = 0; x < v; x++) {

            grid[x][y] = new JLabel((x)+","+(y));

            world.add(grid[x][y]);
L. G.
  • 9,642
  • 7
  • 56
  • 78
0

I did not test it, but try change your code:

grid[x][y] = new JLabel((x)+","+(y));

to:

grid[x][y] = new JLabel((y)+","+(x));
ssuperczynski
  • 3,190
  • 3
  • 44
  • 61