Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何自下而上在网格中添加对象?_Java_Javafx_Gridpane - Fatal编程技术网

Java 如何自下而上在网格中添加对象?

Java 如何自下而上在网格中添加对象?,java,javafx,gridpane,Java,Javafx,Gridpane,Im使用网格窗格视图使用add方法填充网格。通过“添加”的设计,网格从上到下填充每一行,其中位置0,0位于网格的最左上方。添加更多的行,然后在其下方追加,以此类推。是否可以填充我的网格,使第一行位于底部,并向上添加行,使位置0,0位于左下角?实现这一目标需要什么?我查看了GridPane中的不同方法,但找不到这是如何实现的。我的直觉是我需要重写add方法,但我不确定如何实现这个行为 我宁愿不镜像这一点,因为我处理的是图像 以下是为简单起见从类和助手方法中提取的代码要点: public enum

Im使用网格窗格视图使用add方法填充网格。通过“添加”的设计,网格从上到下填充每一行,其中位置0,0位于网格的最左上方。添加更多的行,然后在其下方追加,以此类推。是否可以填充我的网格,使第一行位于底部,并向上添加行,使位置0,0位于左下角?实现这一目标需要什么?我查看了GridPane中的不同方法,但找不到这是如何实现的。我的直觉是我需要重写add方法,但我不确定如何实现这个行为

我宁愿不镜像这一点,因为我处理的是图像

以下是为简单起见从类和助手方法中提取的代码要点:

public enum LawnType
{
    GRASS,
    CRATER
}

lawnData = new LawnType[][] {
        {CRATER,GRASS,GRASS,GRASS,GRASS,GRASS,},
        {GRASS,GRASS,GRASS,GRASS,GRASS,GRASS,},
        {GRASS,GRASS,GRASS,GRASS,GRASS,GRASS,},
        {GRASS,GRASS,GRASS,GRASS,GRASS,GRASS,},
        {GRASS,GRASS,GRASS,GRASS,GRASS,GRASS,},
        {GRASS,GRASS,GRASS,GRASS,GRASS,GRASS,},
    };

GridPane lawnViewer = new GridPane();

for (int x = 0 ; x < data.length ; x++) {
    for (int y = 0 ; y < data[x].length ; y++) {
        ImageView imageView;

        switch(data[x][y]){
            case GRASS:
                imageView = new ImageView(new Image("mower/resources/longgrass1.png"));
                imageView.setFitWidth(gridPixelSize);
                imageView.setFitHeight(gridPixelSize);
                gridPane.add(imageView,x,y);
                break;
            case CRATER:
                imageView = new ImageView(new Image("mower/resources/crater.png"));
                imageView.setFitWidth(gridPixelSize);
                imageView.setFitHeight(gridPixelSize);
                gridPane.add(imageView, x, y);
                break;
            default:
                break;
            }
        }
    }
输出:

您可以将每个图像添加到相对于底行的一行,即数据[x]。长度-1

更换以下各项:

gridPane.add(imageView, x, y);
为此:

gridPane.add(imageView, x, data[x].length - 1 - y)

gridPane.addimageView,x,数据[x]。长度-1-y?为此创建一个答案并接受它。@VGR正在进行一些整理。你能给我一个答案吗?这样我就可以选择答案了?谢谢