Im using a grid pane view to populate a grid using the add() method. By design of the add() the grid populates each row from top to bottom where location (0,0) is at the very top left most of the grid. Adding more rows are then appended below it and so forth. Is it possible to populate my grid so that the first row is at the bottom and add rows upward so that the location (0,0) is located at the bottom left? What is needed to achieve this? Ive looked at the different methods within GridPane but could not find how this is done. My hunch is I need to override the add() method but Im not sure how to implement this behavior.
I would prefer not to mirror this since I am dealing with images.
Here is the gist of code extracted from classes and helper methods for simplicity:
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;
}
}
}
You can add each image at a row relative to the bottom row, which is data[x].length - 1
.
Replace each of these:
gridPane.add(imageView, x, y);
with this:
gridPane.add(imageView, x, data[x].length - 1 - y)