Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7696061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:41:33+00:00 2026-05-31T21:41:33+00:00

I have a simple question. Can a grid automatically resize the objects in it

  • 0

I have a simple question. Can a grid automatically resize the objects in it to fit the grid?

I want to set a max_height and max_width on a grid as well as a min-width and min-height and center that grid in my window.

In my grid, I want to add Spacer Square in all spots. Each spacer has a border. So it will look like an actual grid.

If my grid is 4×4, I want there to be 16 big squares.

If my grid is 16×18, I want there to be 288 squares.

Both options should take up an area of a set amount, the 288 square option having squares a lot smaller than the 16 option in order to fit my grid dimensions.

I checked the gridpane documentation, but am confused if there is an option for me. I don’t know the difference between padding, margins, setmaxwidth, setmaxheight (tried this, didnt change a thing).

double dimension_x=100; //max_width of actual square/spacer/gridspace
double dimension_y=100; //max_height of actual square/spacer/gridspace

int grid_x=100; //number of rows
int grid_y=100; //number of columns
Rectangle[][] rectangles = new Rectangle[grid_x][grid_y];

GridPane grid = new GridPane();
double grid_max_x=800;
double grid_max_y=600;
grid.setHgap(1);
grid.setVgap(1);
grid.setPadding(new Insets(16)); //not sure what this does. Attempt Fail
grid.setEffect(addEffect(Color.web("#202C2F"), .61, 12));
grid.setMaxHeight(grid_max_y); //does nothing that it APPEARS to me

for (int x=0;x<grid_x;x++)
{
    for(int y=0;y<grid_y;y++)
    {
        Rectangle temp = new Rectangle(dimension_x,dimension_y);
        grid.add(temp,x,y);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:41:34+00:00Added an answer on May 31, 2026 at 9:41 pm

    If you want a field of resizable rectangles you don’t need a grid. Just put them on Pane and bind to the pane size:

    public void start(Stage stage) {
        Pane root = new Pane();
    
        final int count = 7; //number of rectangles
    
        NumberBinding minSide = Bindings
                .min(root.heightProperty(), root.widthProperty())
                .divide(count);
    
        for (int x = 0; x < count; x++) {
            for (int y = 0; y < count; y++) {
                Rectangle rectangle = new Rectangle(0, 0, Color.LIGHTGRAY);
    
                rectangle.xProperty().bind(minSide.multiply(x));
                rectangle.yProperty().bind(minSide.multiply(y));
                rectangle.heightProperty().bind(minSide.subtract(2));
                rectangle.widthProperty().bind(rectangle.heightProperty());
                root.getChildren().add(rectangle);
            }
        }
    
        stage.setScene(new Scene(root, 500, 500));
        stage.show();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A fairly simple question for which I have a guess, but I can't find
I have what is undoubtedly a simple question, but I can't seem to find
simple problem with a simple question. I have a string, in C# i can
I have what is probably a really simple, studid question but I can't find
I have a simple question I can't figure out. I have a rails 3
I have a simple question. Is there a way ( using reflections I suppose
I have a simple question and wish to hear others' experiences regarding which is
I have a simple question related to one-line programming. First an example: function test(a)
I have a simple question about Java's XML API and I hope there's a
I have a simple question, but I'm about 80% sure that the answer to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.