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

  • SEARCH
  • Home
  • 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 8899747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:55:58+00:00 2026-06-15T00:55:58+00:00

I recently decided to start using GridLayout because FlowLayout seems somewhat amateur. However, I

  • 0

I recently decided to start using GridLayout because FlowLayout seems somewhat amateur. However, I need help. The parameters when creating the GridLayout are (rows,columns,row space,column space). I have a variable for the row amount and 4 for the column amount, but when I try to add a JButton after everything else, there are 5 columns.
Here is my code:

byte i = 0;
    while(i < main.componentNum)
    {
        comp[i] = new JLabel("component #" + (i+1));
        box[i] = new JComboBox();
        field[i] = new JTextField(5);
        edit[i] = new JButton("edit");

        comp[i].setBackground(Color.WHITE);
        box[i].setBackground(Color.WHITE);
        field[i].setBackground(Color.WHITE);
        edit[i].setBackground(Color.WHITE);

        add(comp[i]);
        add(box[i]);
        add(field[i]);
        add(edit[i]);

        i++;
    }

When I run the above code, I get four columns and it works fine. But when I add a button to the end, I get five. Can anyone tell me how to give one button an entire row?

  • 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-06-15T00:55:59+00:00Added an answer on June 15, 2026 at 12:55 am

    From the Java Docs

    One, but not both, of rows and cols can be zero, which means that any
    number of objects can be placed in a row or in a column.

    Now, without your actual code the sets up the GridLayout, it’s difficult to say, but, if your after maintaining only 4 columns, I would create a GridLayout as follows, new GridLayout(0, 4)

    If you want something more flexible, look into GridBagLayout

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've recently decided to start using some light unit testing to see if it
We recently decided to start using SCM software (yes we probably should have a
I just found out that Google recently decided to start using their own title
The software group I currently work in has recently decided to start documenting our
I've been playing around with ruby recently, and I decided to start a simple
I've been programming for a while, but just recently decided to start developing for
I'm a web-designer and former coder. Recently I decided to start own project and
Recently I decided to optimize some file reading I was doing, because as everyone
I recently decided to use Apache HTTPD (on CentOS - RPM version httpd-2.2.3-45.el5.centos) with
Background info: I've recently decided to take on a project of making a social

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.