N
N
Nickmontt2019-03-04 19:33:27
Java
Nickmontt, 2019-03-04 19:33:27

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

2 answer(s)
N
Nickmontt, 2019-03-04
@Nickmontt

{

for(int i=1;i<=rows;i++)
for(int j=1;j<=cols;j++) {
changed to
for(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 the
Rectangle 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.5c7d6412ea374966795129.png5c7d641a2ec5d483711786.png

D
Dmitry Alexandrov, 2019-03-04
@jamakasi666

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 question

Ask a Question

731 491 924 answers to any question