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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:51:17+00:00 2026-05-18T23:51:17+00:00

I am in the process of making a GUI which shows three JToolBars above

  • 0

I am in the process of making a GUI which shows three JToolBars above a big JPanel. These toolbars are collectively very large, so I’m using a FlowLayout to make them wrap to the next line if they reach the JFrame border. The problem is that when they wrap to the next line, they become hidden by the JPanel below.. I wish I could force the JPanel containing the toolbars to grow enough to show all toolbars..

Is there a way to do this? Or is there another way to make these toolbars visible?

  • 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-18T23:51:18+00:00Added an answer on May 18, 2026 at 11:51 pm

    I have run into this problem before. I found the best solution is to use a modified version of FlowLayout that takes into account vertical changes and wraps them to the next line. Here is the code for such a layout.

    import java.awt.*;
    
    /**
      * A modified version of FlowLayout that allows containers using this
      * Layout to behave in a reasonable manner when placed inside a
      * JScrollPane
      * @author Babu Kalakrishnan
      * Modifications by greearb and jzd
      */
    
     public class ModifiedFlowLayout extends FlowLayout {
           public ModifiedFlowLayout() {
                  super();
               }
    
               public ModifiedFlowLayout(int align) {
                  super(align);
               }
           public ModifiedFlowLayout(int align, int hgap, int vgap) {
              super(align, hgap, vgap);
           }
    
           public Dimension minimumLayoutSize(Container target) {
              // Size of largest component, so we can resize it in
              // either direction with something like a split-pane.
              return computeMinSize(target);
           }
    
           public Dimension preferredLayoutSize(Container target) {
              return computeSize(target);
           }
    
           private Dimension computeSize(Container target) {
              synchronized (target.getTreeLock()) {
                 int hgap = getHgap();
                 int vgap = getVgap();
                 int w = target.getWidth();
    
                 // Let this behave like a regular FlowLayout (single row)
                 // if the container hasn't been assigned any size yet
                 if (w == 0) {
                    w = Integer.MAX_VALUE;
                 }
    
                 Insets insets = target.getInsets();
                 if (insets == null){
                    insets = new Insets(0, 0, 0, 0);
                 }
                 int reqdWidth = 0;
    
                 int maxwidth = w - (insets.left + insets.right + hgap * 2);
                 int n = target.getComponentCount();
                 int x = 0;
                 int y = insets.top + vgap; // FlowLayout starts by adding vgap, so do that here too.
                 int rowHeight = 0;
    
                 for (int i = 0; i < n; i++) {
                    Component c = target.getComponent(i);
                    if (c.isVisible()) {
                       Dimension d = c.getPreferredSize();
                       if ((x == 0) || ((x + d.width) <= maxwidth)) {
                          // fits in current row.
                          if (x > 0) {
                             x += hgap;
                          }
                          x += d.width;
                          rowHeight = Math.max(rowHeight, d.height);
                       }
                       else {
                          // Start of new row
                          x = d.width;
                          y += vgap + rowHeight;
                          rowHeight = d.height;
                       }
                       reqdWidth = Math.max(reqdWidth, x);
                    }
                 }
                 y += rowHeight;
                 y += insets.bottom;
                 return new Dimension(reqdWidth+insets.left+insets.right, y);
              }
           }
    
           private Dimension computeMinSize(Container target) {
              synchronized (target.getTreeLock()) {
                 int minx = Integer.MAX_VALUE;
                 int miny = Integer.MIN_VALUE;
                 boolean found_one = false;
                 int n = target.getComponentCount();
    
                 for (int i = 0; i < n; i++) {
                    Component c = target.getComponent(i);
                    if (c.isVisible()) {
                       found_one = true;
                       Dimension d = c.getPreferredSize();
                       minx = Math.min(minx, d.width);
                       miny = Math.min(miny, d.height);
                    }
                 }
                 if (found_one) {
                    return new Dimension(minx, miny);
                 }
                 return new Dimension(0, 0);
              }
           }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm in the process of making a Python-based personal assistant/question answerer, which, in my
I am currently in process of making our application Large Address Aware. As experience
I am currently in the process of making a WordPress Plugin which is going
I am in the process of making a program, which allows you to view
I'm in the process of making an application, but I've encountered an problem which
In the process of making an old webpage standard compliant, the validator came across
I am in the process of making a website that involves a shopping cart.
I'm on the process of making a dropdown widget. The menu the expands down
I'm in the process of making a Rails application be able to run on
How could I track down the death of a child process without making the

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.