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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:26:33+00:00 2026-05-14T02:26:33+00:00

I used myPanel.setLayout(new BoxLayout(myPanel, BoxLayout.Y_AXIS)); to order panels vertically (one under another one). But

  • 0

I used myPanel.setLayout(new BoxLayout(myPanel, BoxLayout.Y_AXIS)); to order panels vertically (one under another one). But myPanel defined in the shown way change the included panel. In more details, it tries to set the same hight and width for the included panels. Can it be changed? Can BoxLayout adopt size of the included elements?

ADDED:

So, as it is recommended, let’s read the documentation:

BoxLayout attempts to arrange
components at their preferred widths
(for horizontal layout) or heights
(for vertical layout). For a
horizontal layout, if not all the
components are the same height,
BoxLayout attempts to make all the
components as high as the highest
component. If that’s not possible for
a particular component, then BoxLayout
aligns that component vertically,
according to the component’s Y
alignment. By default, a component has
a Y alignment of 0.5, which means that
the vertical center of the component
should have the same Y coordinate as
the vertical centers of other
components with 0.5 Y alignment.

In my case, I have the Y_AXIS layout. Is it the “vertical” layout? If it is the case, the components should be arranged at their preferred heights. What is the “preferred heights”?

Next, it is written “for a horizontal layout, if not all the components are the same height, BoxLayout attempts to make all the components as high as the highest component”. So, I assume that for the vertical layout. BoxLayout will try to make all components as broad as the broadest one. Right? And what about the “preferred heights” used in the vertical layout?

It is also written that if it is not possible for the horizontal layout to make all components as hight as the highest component it will align the component vertically. What does it mean “to align vertically”? Is it not strange that the horizontal layout aligns component vertically?

ADDED 2:

The problem of the vertical layout is that it makes all elements as broad as the window. As a result, elements included into the JPanel, with the vertical box layout, will not keep their proportions. And this is exactly what I want to avoid.

  • 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-14T02:26:33+00:00Added an answer on May 14, 2026 at 2:26 am

    Use GridBagLayout instead. It is a pain to configure manually, but there are tools that can write the constraints for you (most notably NetBeans’ GUI builder) — and it gives you total control over how each of the components are stretched and located.

    You can set alignments, fills, insets, margins, how the free space gets distributed, how the final bounds will be calculated, and so on. And it is not so difficult to write looping code to add whole collections of components with similar constraints in either rows or columns.

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

Sidebar

Related Questions

We used to use SourceSafe, and one thing I liked about it was that
I used Grails recently, and added Grails plugin for JQuery, but I don't think
I used this p.test { white-space: nowrap; overflow: hidden; text-overflow: ellipsis;} but it's not
I used jarsigner to sign my jar file. But I got a warning: Warning:
We used the undocumented xp_fileexist stored procedure for years in SQL Server 2000 and
I used the LINQ to SQL designer in Visual Studio to create an object
Never used a cache like this before. The problem is that I want to
I used to work in a place where a common practice was to use
I used jQuery to set hover callbacks for elements on my page. I'm now
When used like this: import static com.showboy.Myclass; public class Anotherclass{} what's the difference between

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.