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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:25:16+00:00 2026-06-07T23:25:16+00:00

I am trying to construct the following resizeable JPanel: +———————–+ | | | |

  • 0

I am trying to construct the following resizeable JPanel:

+-----------------------+
|                       |
|                       |
|                       |
|                       |
|                       |
|     JScrollPane       |
|     (containing a     |
|        JTable)        |
|                       |
|                       |
|                       |
|                       |
|                       |
+-----------+-----------+
|  button1  |    b2     |
+-----------+-----------+

I want to button1 and b2 to always be the same width, meaning that when the whole component is resized horizontally, both buttons should gain or lose the same width. There should be no space between the buttons themselves nor between the buttons and the panel’s border. That is, the buttons should always take up all available horizontal space. Note that the text on the buttons is of different length.

When the component is resized vertically, I want the JScrollPane to gain the new height, while the row with the buttons should always remain the same height (essentially button1.getPreferedSize().getHeight()).

I have tried a whole bunch of different LayoutManagers. The closest I got was to put the two buttons in a new JPanel and setting the LayoutManger of that panel to new GridLayout(0,2). That at least maintained a uniform width for both buttons and filled out all horizontal space. However, they still changed their height when the panel was resized vertically.

With other LayoutManagers such as GroupLayout I was able to maintain the same width by linking the buttons (groupLayout.linkSize(button1, b2)), but unable to get them to fill the whole horizontal space.

Whats the best way to achieve this and what LayoutManager should be used?

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

    I would highly suggest checking out MigLayout. It’s a very flexible and easy to use layoutmanager.

    If you don’t want to use that, I would suggest making a JPanel with a BorderLayout and put the scrollpane in the center of the borderlayout. Then, make another JPanel with a GridLayout that’s 1 row and 2 columns, and add both of the buttons to that. Then, add that panel to the south region of the JPanel with the borderlayout.

    The code would look something like this:

        JPanel mainPanel = new JPanel();
        mainPanel.setLayout(new BorderLayout());
    
        JPanel tablePanel = new JPanel();
        JScrollPane jsp = new JScrollPane(new JTable());
        tablePanel.add(jsp);
        mainPanel.add(jsp, BorderLayout.CENTER);
    
        JPanel buttonPanel = new JPanel();
        buttonPanel.setLayout(new GridLayout(1, 2));
        JButton button1 = new JButton("Button 1");
        JButton button2 = new JButton("Button 2");
        buttonPanel.add(button1);
        buttonPanel.add(button2);
        mainPanel.add(buttonPanel, BorderLayout.SOUTH);
    
        this.add(mainPanel);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to construct a layout similar to the following: +---+---+---+ | | |
I'm trying construct a PostgreSQL query that does the following but so far my
I'm using MySQL and I'm trying to construct a query to do the following:
I am trying to construct an equilateral triangle with the following code, but I
I am trying to construct a regular expression that will match the following URL:
I'm trying to construct an algorithm that runs at O(nb) time with the following
I'm trying to construct the following 14*14 array i C: [I 0; 0 -I],
I'm trying to construct the following div element using jQuery: <div> <p>Hello</p> <p>Stack Overflow</p>
I'm trying to construct a contrapositive for the following statement: If A is 0
Trying to construct a Request with Network.HTTP.Conduit package. The instructions are: The constructor for

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.