We help IT Professionals succeed at work.
Get Started

Problem getting gridbag to give me symetry

Dawkins
Dawkins asked
on
270 Views
Last Modified: 2008-03-10
Hi all,

I can't seem to get the gridbag layout to stop adjusting the size of cells relative to each other.  I have two lists side by side, and I want them to split the display exactly 50/50 no matter what.  

When neither has anything in, they are the same size.  However, when one of them gets some list elements, the amount of x axis room allocated to it increases, making the display lopsided.  Is there a way to stop this happening?  I thought that was the point of the weights?  

Here is the code (note: This isn't the exact code - I've cut several of the UI components out to keep it simple but the principle is the same)

    buildConstraints(constraints, 0, 0, 1, 1, 50, 100);
    constraints.fill = GridBagConstraints.BOTH;
    JList list1 = new JList(nameList);
    list1 .setLayoutOrientation(JList.VERTICAL);
    list1 .setVisibleRowCount( -1);
    JScrollPane pane1= new JScrollPane(
      list1 , JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    gridbag.setConstraints(pane1, constraints);
    mainPane.add(pane1);

    buildConstraints(constraints, 1, 0, 1, 1, 50, 0);
    constraints.fill = GridBagConstraints.BOTH;
    JList list2 = new JList();
    list2 .setLayoutOrientation(JList.VERTICAL);
    list2 .setVisibleRowCount( -1);
    JScrollPane pane2 = new JScrollPane(
      list2 , JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    gridbag.setConstraints(pane2 , constraints);
    mainPane.add(pane2 );
Comment
Watch Question
Java Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
This problem has been solved!
Unlock 1 Answer and 13 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE