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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:05:05+00:00 2026-05-12T08:05:05+00:00

the problem is in centered layout of components, GridBagLayout always ‘sits’ in center of

  • 0

the problem is in centered layout of components, GridBagLayout always ‘sits’ in center of JPanel, so I don’t care how it will layout components inside, my problem is where these components will start laying out on a panel.

I tried with:

panel.setAlignmentX( JPanel.LEFT_ALIGNMENT );

but it did not helped.

Any idea?

  • 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-12T08:05:05+00:00Added an answer on May 12, 2026 at 8:05 am

    You need to add at least one component that will fill the horizontal space. If you don’t have such a component you can try this:

    GridBagConstraints noFill = new GridBagConstraints();
    noFill.anchor = GridBagConstraints.WEST;
    noFill.fill = GridBagConstraints.NONE;
    
    GridBagConstraints horizontalFill = new GridBagConstraints();
    horizontalFill.anchor = GridBagConstraints.WEST;
    horizontalFill.fill = GridBagConstraints.HORIZONTAL;    
    
    panel.add(new JLabel("Left Aligned"), noFill);
    panel.add(Box.createHorizontalGlue(), horizontalFill);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't see where is problem, but .topbar isn't centered as it should be...
The titles says it. I want a 2-column CSS layout that: is centered -
The goal is to have min-width: 960px; with centered layout and additional 'wings' for
I'm trying to find a rational solution for a layout problem in iOS. I
I want to inflate a XML-Layout-File in a custom ViewGroup Class, my Problem is
Ok, I had a simple layout problem a week or two ago. Namely sections
I'm trying to make a centered, 100% high layout that has NO FIXED width
I'm implementing pagination, and it needs to be centered. The problem is that the
I am working on this layout (Vertical centered,fluid middle div with, fixed heights) http://jsfiddle.net/chchrist/uyzJj/13/
I have a problem with the page heading to be left-center of background irrespective

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.