GridLayout坐标 [英] GridLayout coordinates

查看:200
本文介绍了GridLayout坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  int s = 4;所以我想你会通过这段代码来理解我的问题。 
int v = 4;

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

grid = new JLabel [s] [v]; (int y = 0; y = 0; x--){



) {

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

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

现在我得到一个坐标为的网格:

  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

但我想得到:

  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

我没有测试它,但试一试:

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

(int x = 0; x
grid [x] [y] = new JLabel + +(Y));

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


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..

解决方案

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]);

这篇关于GridLayout坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆