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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:13:24+00:00 2026-06-13T23:13:24+00:00

I am running into a problem with GridBagLayouts. I have a few components laid

  • 0

I am running into a problem with GridBagLayouts.

I have a few components laid out as shown in the picture below:

enter image description here

I want the “center” component to be able to move above the bottom edge of “top-right” if the “top” component shrinks small enough. However, this obviously causes a problem since it would have to be in a different row in the grid to be able to do so.

To solve this – I define the entire right column as its own container, with its own layout manager. I’d expect the two columns to be able to behave independently, however I get the same problem! I don’t see how the two layout managers could possibly be interacting still. Can anyone possibly explain what my problem is?

Here is the relevant code (in my class extending Applet):

public void init(){
    addComponents();
}

private void addComponents(){
    setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();

    Left left = new Left();
    Top top = new Top();
    Center center = new Center();
    TopRight topRight = new TopRight();
    BottomRight bottomRight = new BottomRight();
    Bottom bottom = new Bottom();

    topRight.setPreferredSize(new Dimension(200,200));
    top.setPreferredSize(new Dimension(0,200));
    center.setPreferredSize(new Dimension(0,100));
    container.setPreferredSize(new Dimension(200,200));

    c.fill = GridBagConstraints.BOTH;

    c.gridx = 0; c.gridy = 0;
    c.gridwidth = 1; c.gridheight = 3;
    c.weightx = 0.2; c.weighty = 1.0;
    this.add(left,c);

    c.gridx = 1; c.gridy = 0;
    c.gridwidth = 1; c.gridheight = 1;
    c.weightx = 0.8; c.weighty = 0.8;
    this.add(top,c);

    c.gridx = 1; c.gridy = 1;
    c.gridwidth = 1; c.gridheight = 1;
    c.weightx = 0.8; c.weighty = 0.0;
    this.add(center,c);

    c.gridx = 1; c.gridy = 2;
    c.gridwidth = 1; c.gridheight = 1;
    c.weightx = 0.8; c.weighty = 0.2;
    this.add(bottom,c);

    JPanel container = new JPanel();
    container.setLayout(new GridBagLayout());

    c.gridx = 2; c.gridy = 0;
    c.gridwidth = 1; c.gridheight = 3;
    c.weightx = 0.0; c.weighty = 1.0;
    this.add(container,c);

    GridBagConstraints c2 = new GridBagConstraints();
    c2.fill = GridBagConstraints.BOTH;

    c2.gridx = 0; c2.gridy = 0;
    c2.gridwidth = 1; c2.gridheight = 1;
    c2.weightx = 0.0; c2.weighty = 0.0;
    container.add(topRight,c2);

    c2.gridx = 0; c2.gridy = 1;
    c2.gridwidth = 1; c2.gridheight = 1;
    c2.weightx = 0.0; c2.weighty = 1.0;
    container.add(bottomRight,c2);
}

Note: Each of the components shown (left, top, etc) is an extension of JPanel – each with its paint(Graphics g) method overridden to fill it with some color.

Thanks in advance, and sorry for the long read,

Jonathan

  • 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-13T23:13:25+00:00Added an answer on June 13, 2026 at 11:13 pm

    I fixed the problem. It had something to do with me setting the preferred height of the Top component unnecessarily – when I removed that line it worked like I was wanting.

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

Sidebar

Related Questions

Running into a problem. I have a table defined to hold the values of
i am running into a problem that i have a jquery modal popup in
I'm running into problem about redirect stdout of multi process. Assuming I have process
I'm running into a problem with JAXB unmarshalling that I have no clue how
I've been running into this problem a lot lately. I have an NSMutableArray called
I keep running into this problem over and over. I have a view with
I am running into a problem with HttpServlet request. I have an application in
I have been running into a problem with python's re module. This is the
I'm running into a problem with method overwriting. Look at the src code below,
hey guys m running into a problem, i have a forloop n in that

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.