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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:34:16+00:00 2026-06-12T04:34:16+00:00

Ok, so here’s the setup: 3 components in a panel (a JScrollpane, a JPanel,

  • 0

Ok, so here’s the setup:
3 components in a panel (a JScrollpane, a JPanel, and a JTabbedPane).

this.plan = new JPanel();
this.plan.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();

//The ScrollPane
this.SrsDocument = new JTextArea();
this.SrsDocument.setEditable(false);
this.SrsDocumentScroll = new JScrollPane(this.SrsDocument);
c.fill = GridBagConstraints.BOTH;
c.weightx = 0.33;
c.weighty = 1.0;
c.gridx = 0;
this.plan.add(this.SrsDocumentScroll, c);
...
//The Panel
this.TreePanel = new JPanel();
this.TreePanel.setLayout(new BoxLayout(this.TreePanel, BoxLayout.Y_AXIS));
this.Tree = new JTree();
((DefaultTreeModel)(this.Tree.getModel())).setRoot(null);
this.Tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
this.TreeScroll = new JScrollPane(this.Tree);
this.TreePanel.add(this.TreeScroll);
c.gridx = 1;
c.weightx = 0.33;
this.plan.add(this.TreePanel, c);
...
//The TabbedPane
this.currentFunction = new JTabbedPane();
c.gridx = 2;
c.weightx = 0.33;
this.plan.add(this.currentFunction, c);

I had expected this layout to have 3 columns, all with even width. yet the initial display has this.SrsDocumentScroll much narrower in width then the other 2. Additionally, as I resize the window this.SrsDocumentScroll is consumed while the other do not resize till this.SrsDocumentScroll is completely consumed. I had expected all three to resize equally as this.plan resizes. Does weightx not determine how to distribute space when resizing as I had assumed?

I should also add that the contents of the three are: textArea is filled with text, tree as just a root, and tabbed pane has just one tab. The contents of all change dynamically, but that resizing is not the behavior im having troubles with, just the resizing of the window and it consumes (as window shrinks) leftmost->rightmost instead of equally.

EDIT: This is ment to be more of a test, thats why I used 0.33 for my weightx’s. the final result is ment to weight more heavily on the tabbedpane then the others. more like (0.25,0.25,0.5) but more manageable then just those values if you folo me.

  • 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-12T04:34:17+00:00Added an answer on June 12, 2026 at 4:34 am

    I had expected this layout to have 3 columns, all with even width. … I had expected all three to resize equally …

    Much will likely depend on the preferredSize, maximumSize and minimumSize of the components added to the GridBagLayout. If you want equal sized components in 3 columns, don’t use a GridBagLayout but rather a GridLayout(1, 3) (for 1 row, 3 columns) or GridLayout(0, 3) (for 3 columns and variable number of rows).

    To show you what I mean, run the code below, commenting or uncommenting these two lines:

          // setSizes(btn, scrollpane);
          // setSizes(label, scrollpane);
    

    GridBagTest.java

    import java.awt.*;
    import javax.swing.*;
    
    public class GridBagTest {
       public static void main(String[] args) {
          JPanel panel = new JPanel(new GridBagLayout());
    
          JTextArea textarea = new JTextArea(5, 30);
          JScrollPane scrollpane = new JScrollPane(textarea);
    
          JButton btn = new JButton("Foo");
    
          JLabel label = new JLabel("Bar");
          label.setBorder(BorderFactory.createTitledBorder("Bar"));
    
          GridBagConstraints gbc = new GridBagConstraints();
          gbc.fill = GridBagConstraints.BOTH;
          gbc.gridheight = 1;
          gbc.gridwidth = 1;
          gbc.gridx = 0;
          gbc.gridy = 0;
          gbc.weightx = 1.0;
          gbc.weighty = 1.0;
    
          panel.add(scrollpane, gbc);
    
          gbc.gridx = 1;
          panel.add(btn, gbc);
    
          gbc.gridx = 2;
          panel.add(label, gbc);
    
          // **** comment or uncomment the lines below
          // setSizes(btn, scrollpane);
          // setSizes(label, scrollpane);
    
          JFrame frame = new JFrame("GBC Test");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.getContentPane().add(panel);
          frame.pack();
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
    
       }
    
       private static void setSizes(Component changeComponent,
             Component templateComponent) {
          changeComponent.setPreferredSize(templateComponent.getPreferredSize());
          changeComponent.setMaximumSize(templateComponent.getMaximumSize());
          changeComponent.setMinimumSize(templateComponent.getMinimumSize());
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the code in a function I'm trying to revise. This example works
Here's the basic setup: I have a thin bar at the top of a
Here is an example. foreach (var doc in documents) { var processor = this.factory.Create();
Here's what I'm trying to accomplish with this program: a recursive method that checks
Here is the css: #content ul { font-size: 12px; } I am trying this:
Here is the code I'm using inside my AsyncTask DefaultHttpClient httpClient = new DefaultHttpClient();
here is how i call the following function: List<decimal> numbers = new List<decimal>(); numbers.Add(210m);
Here is the setup: dynamically generates content for a number of items which need
Here's the code require_once 'functions.php'; require_once 'cfg.php'; $mysqli = new mysqli($dbhost, $dbuser, $dbpass, $db);
Here is my problem.. I have the option to create(add) two new input fields,

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.