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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:19:09+00:00 2026-05-29T10:19:09+00:00

I have browsed around and haven’t found a solution that specifically tailors to my

  • 0

I have browsed around and haven’t found a solution that specifically tailors to my situation. I have a panel that I display in a dialog box:

//create dialog panel
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.add(headerPanel);
panel.add(type1Panel);
panel.add(type2Panel);
panel.add(type3Panel);
panel.add(type4Panel);
panel.add(type5Panel);
panel.add(type6Panel);

int result = JOptionPane.showConfirmDialog(null, panel, "Please enter values.", JOptionPane.OK_CANCEL_OPTION);

The size of the last two panels, type5 & type6, are of equal size so they look fine. However, the header and first 4 panels are of different sizes and I would like them all to be left aligned. As of yet I haven’t found a good solution as how to fix this.

Question is, how can I left align the first 5 panels, but not last 2? If not how can I left align them all? The setalignmentx() isn’t available for panels. I’ve tried using GridLayout, but then the width of the gui’s main window is rather large and doesn’t fit nicely onto the screen, hence the BoxLayout along Y axis.Thanks for any help or suggestions.

  • 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-29T10:19:10+00:00Added an answer on May 29, 2026 at 10:19 am

    Here is an example that will left align all the JPanels added to the panel used as a container.

       JPanel a = new JPanel();
       JPanel b = new JPanel();
       JPanel c = new JPanel();
    
       a.setBackground( Color.RED );
       b.setBackground( Color.GREEN  );
       c.setBackground( Color.BLUE );
    
       a.setMaximumSize( new Dimension(  10, 10) );
       b.setMaximumSize( new Dimension(  50, 10) );
    
       a.setAlignmentX( Component.LEFT_ALIGNMENT );//0.0
       b.setAlignmentX( Component.LEFT_ALIGNMENT );//0.0
       c.setAlignmentX( Component.LEFT_ALIGNMENT );//0.0
    
       JPanel panel = new JPanel();
       panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
       panel.add(a);
       panel.add(b);
       panel.add(c); 
    
       int result = JOptionPane.showConfirmDialog(null, panel, "Please enter values.", JOptionPane.OK_CANCEL_OPTION);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've browsed around for an answer, but I haven't found anything that really says,
I have browsed thru other postings on S/O, but I can't find a solution
I browsed around here on Stackoverflow and found this topic : https://stackoverflow.com/questions/279/aspnet-visual-studio-and-subversion-how-to-integrate However that
I have a problem that I cannot seem to find a solution for. I
I have a large project in Vb.net which drives a web browser control around.
We have a application which is triggered from browser. This application consumes around 800
I have browsed lift's MegaProtoUser and encountered this construction: ??(Last Name) . Can anyone
I have an ASP.NET web application the entire site is browsed over HTTPS using
I have a Browser Helper Object project in c# that (obviously) references shdocvw.dll. I
I have a website that's working with Facebook Connect (or Facebook for Websites as

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.