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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:39:15+00:00 2026-05-13T05:39:15+00:00

I am attempting to draw a sidebar for a project that I am working

  • 0

I am attempting to draw a sidebar for a project that I am working on. I chose to use GridBagLayout because I became frustrated with the limitations of BoxLayout. Could someone help explain what I am doing wrong. What I want is for the side bar to contain two JPanels. The code that I have places them halfway down the sidebar instead of at the top. Could someone explain what I am missing here.

    JPanel sideBar = new JPanel();
    sideBar.setBounds(0, 0, 180, (int)this.getBounds().getHeight());
    sideBar.setLayout(new GridBagLayout());


    JPanel optionBar = new JPanel();
    optionBar.setBorder(BorderFactory.createTitledBorder("Box1"));
    optionBar.setLayout(new GridBagLayout());


    JPanel buttonBar = new JPanel();
    buttonBar.setBorder(BorderFactory.createTitledBorder("Options"));
    buttonBar.setLayout(new GridBagLayout());


    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridx = 0;
    c.ipady = 5;
    c.insets = new Insets(10,0,0,0);


    JButton simplify;
    simplify = new JButton("Open");
    simplify.addActionListener( this.listener );
    c.gridy = 0;
    buttonBar.add(simplify, c);

    JButton mergeButton;
    mergeButton = new JButton("Close");
    mergeButton.addActionListener( this.listener );
    c.gridy = 1;
    buttonBar.add(mergeButton, c);

    JButton splitButton;
    splitButton = new JButton("Merge");
    splitButton.addActionListener( this.listener );
    c.gridy = 2;
    buttonBar.add(splitButton, c);

    c.insets = new Insets(0,5,5,5);
    c.gridy = 0;
    sideBar.add(optionBar, c);

    c.gridy = 1;
    c.ipadx = 70;
    sideBar.add(buttonBar, c);

    return(sideBar);
  • 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-13T05:39:15+00:00Added an answer on May 13, 2026 at 5:39 am

    GridBagLayout will only allocate enough vertical space that a component requires, leaving the rest blank. I expect you’re seeing your side bar components centred vertically?

    In order to “push” the components out, you need to set a vertical weight. If you set the weighty constraint to 1.0 on your last component, it will take up all remaining vertical space for that component and push the rest to the top. (You may also need to anchor that last panel to GridBagConstraints.NORTH).

    Try c.weighty = 1.0 before sideBar.add(buttonBar, c);

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

Sidebar

Related Questions

I am attempting to use jqplot to draw a stacked bar chart with the
Attempting to print out a list of values from 2 different variables that are
When attempting to compile my C# project, I get the following error: 'C:\Documents and
When attempting to open a project from source control on a newly formatted pc,
In attempting to use the Performance Tools on an ASP.NET website I'm getting various
I'm attempting to draw text to the screen using GLUT in 2d. I want
My program is attempting to draw grammars in C# & WPF. I have: 1
Using OpenGL I'm attempting to draw a primitive map of my campus. Can anyone
When attempting to write/read cookies that have brackets in the name, it seems like
I am attempting to use Reflection in C# to determine at runtime the type

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.