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 348331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:21:16+00:00 2026-05-12T11:21:16+00:00

I want to show the status of some files in a Java GUI. Each

  • 0

I want to show the status of some files in a Java GUI. Each file has a label and a button, the colour of the button represents the status of the file and clicking performs various operations. All this is working, the problem is that they are not showing correctly. I want it to appear as

[Label 1] [File 1] [File 2] [Label 2]
[Label 3] [File 3] [File 4] [Label 4]
etc.

To do this I have made a panel with a GridLayout

 new JPanel(new GridLayout((list.size() + 1) /2,4,3,3));

This works unless there is an odd number of files. Then the grid resizes itself, for example with 3 files I will get a 2×3 grid so label 2 shows on the next line. If I check for an odd number and then add 2 new JPanels after all the other controls it shows correctly but I was wondering if there is a better way of doing this.

Thanks

  • 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-12T11:21:17+00:00Added an answer on May 12, 2026 at 11:21 am

    Looking at the JavaDoc for GridLayout.setColumns, it appears that not specifying the row count will cure your ills.

    Sets the number of columns in this layout to the specified value. Setting the number of columns has no affect on the layout if the number of rows specified by a constructor or by the setRows method is non-zero. In that case, the number of columns displayed in the layout is determined by the total number of components and the number of rows specified. (my emphasis)

    Try this:

    new JPanel(new GridLayout(0,4,3,3));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a desktop GUI in swing , i want to show status of
I want to show HTML content inside Flash. Is there some way to do
I want to show a chromeless modal window with a close button in the
...I want to Show the 'delete' button when user is an admin, and show
Q: I want to break the loop if some exception has been caught in
I am loading some JSON data in an AsyncTask, as I want to show
In my application, i want to show the status of ( whether the connection
In my Java app, I want to query the MySQL status statistics. I'm adding
I want show annotation view (above one of my pin) after load map. For
hii I want show a pop up Dialog box when i click on 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.