Answer the question
In order to leave comments, you need to log in
How to change the size of squares in a fixed field, based on the number of all its cells??
I have a square field, which I divide into cells, but the size of these cells is fixed and with a small number of rows and columns on the field, there is a lot of empty space. How to create a field with cells, the size of which will change along with the size of its rows and columns?
void repanit(){
pane.getChildren().clear();
boolean[][] b = game.getPole();
for(int i=1;i<=rows;i++)
for(int j=1;j<=cols;j++) {
Rectangle pole = new Rectangle(j*20, i*20, 20, 20);
// attempts to resize Rectangle pole = new Rectangle(j*(400/cols), i*(400/rows), 400/cols, 400/rows);
pole.setStroke(Color.BLACK);
pane.getChildren().add(pole);
}
}
Answer the question
In order to leave comments, you need to log in
{
for(int i=1;i<=rows;i++)
for(int j=1;j<=cols;j++) {
changed tofor(int i=0;i<=rows;i++)
for(int j=0;j<=cols;j++)
a,Rectangle pole = new Rectangle(j*20, i*20, 20, 20);
on theRectangle pole = new Rectangle(j*(430/cols), i*(430/rows), 430/cols, 430/rows);
. Everything worked out, it was necessary that they did not stretch to the size of the window, but decreased when divided into larger parts.
Dynamically calculate? It's not entirely clear what exactly you want. Is it necessary that when the window changes, the rectangles always stretch to fit?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question