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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:48:21+00:00 2026-06-14T13:48:21+00:00

Hey I’m attempting to align all panels within a panel to the left of

  • 0

Hey I’m attempting to align all panels within a panel to the left of the larger panel.

here is a picture of what I’m currently faced with:

Box panel layout

For the master panel (the one that contains all other panels – I shall call it the master!)
I’m using the following code when creating it:

    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

For each of the panels within it I’m also using the BoxLayout, but I’ve tried things like [jpanel].setAlignmentX(Component.LEFT_ALIGNMENT) on each panel but that doesn’t seem to work.

Any help would be appreciated!

🙂

edit: for the “Dimensions of box(m):” label, is there any way of aligning that to the top of the panel it’s contained in? It’s in a panel of its own.

edit: Once fixed:

JPanel problem once fixed

Solution below, thanks all for your help 🙂

  • 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-14T13:48:22+00:00Added an answer on June 14, 2026 at 1:48 pm

    You have a number of possibilities, depending on you over all needs.

    All I’ve done here is used compound panels and using GridBagLayout to adjust the layouts

    enter image description here

    public class BadLayout03 {
    
        public static void main(String[] args) {
            new BadLayout03();
        }
    
        public BadLayout03() {
            EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    try {
                        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
                    }
    
                    JFrame frame = new JFrame();
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.setLayout(new BorderLayout());
                    frame.add(new MasterPane());
                    frame.pack();
                    frame.setLocationRelativeTo(null);
                    frame.setVisible(true);
                }
            });
        }
    
        public class MasterPane extends JPanel {
    
            public MasterPane() {
                setLayout(new GridBagLayout());
                GridBagConstraints gbc = new GridBagConstraints();
                gbc.gridx = 0;
                gbc.gridy = 1;
                gbc.weightx = 1;
                gbc.fill = GridBagConstraints.HORIZONTAL;
                gbc.insets = new Insets(4, 4, 4, 4);
                gbc.anchor = GridBagConstraints.WEST;
                add(new DimensionsPane(), gbc);
                gbc.gridy++;
                add(new ColorPane(), gbc);
                gbc.gridy++;
                add(new ReinforementPane(), gbc);
                gbc.gridy++;
                add(new SealableTopPane(), gbc);
                gbc.gridy++;
                add(new CardGradePane(), gbc);
                gbc.gridy++;
                add(new QuantityPane(), gbc);
                gbc.gridy++;
                add(new OrderPricePane(), gbc);
            }
    
        }
    
        public class DimensionsPane extends JPanel {
    
            public DimensionsPane() {
                setLayout(new GridBagLayout());
                GridBagConstraints gbc = new GridBagConstraints();
                gbc.gridx = 0;
                gbc.gridy = 1;
                gbc.weightx = 1;
                gbc.anchor = GridBagConstraints.WEST;
                add(new JLabel("Dimensions of box (m):"), gbc);
    
                gbc.gridx = 1;
                gbc.gridy = 0;
                gbc.anchor = GridBagConstraints.EAST;
                add(new JLabel("Length: 33.0"), gbc);
                gbc.gridy++;
                add(new JLabel("Width: 3.0"), gbc);
                gbc.gridy++;
                add(new JLabel("Height: 3.0"), gbc);
            }
    
        }
    
        public class ColorPane extends JPanel {
    
            public ColorPane() {
                setLayout(new GridBagLayout());
                GridBagConstraints gbc = new GridBagConstraints();
                gbc.gridx = 0;
                gbc.gridy = 0;
                gbc.weightx = 1;
                gbc.anchor = GridBagConstraints.WEST;
                add(new JLabel("Colour :"), gbc);
    
                gbc.gridx = 1;
                gbc.gridy = 0;
                gbc.anchor = GridBagConstraints.EAST;
                add(new JLabel("0"), gbc);
            }
    
        }
    
        public class ReinforementPane extends JPanel {
    
            public ReinforementPane() {
                setLayout(new GridBagLayout());
                GridBagConstraints gbc = new GridBagConstraints();
                gbc.gridx = 0;
                gbc.gridy = 0;
                gbc.weightx = 1;
                gbc.anchor = GridBagConstraints.WEST;
                add(new JLabel("Reinforcement :"), gbc);
    
                gbc.gridx = 1;
                gbc.gridy = 0;
                gbc.anchor = GridBagConstraints.EAST;
                add(new JLabel("None"), gbc);
            }
    
        }
    
        public class SealableTopPane extends JPanel {
    
            public SealableTopPane() {
                setLayout(new GridBagLayout());
                GridBagConstraints gbc = new GridBagConstraints();
                gbc.gridx = 0;
                gbc.gridy = 0;
                gbc.weightx = 1;
                gbc.anchor = GridBagConstraints.WEST;
                add(new JLabel("Selable top :"), gbc);
    
                gbc.gridx = 1;
                gbc.gridy = 0;
                gbc.anchor = GridBagConstraints.EAST;
                add(new JLabel("No"), gbc);
            }
    
        }
    
        public class CardGradePane extends JPanel {
    
            public CardGradePane() {
                setLayout(new GridBagLayout());
                GridBagConstraints gbc = new GridBagConstraints();
                gbc.gridx = 0;
                gbc.gridy = 0;
                gbc.weightx = 1;
                gbc.anchor = GridBagConstraints.WEST;
                add(new JLabel("Grade of card:"), gbc);
    
                gbc.gridx = 1;
                gbc.gridy = 0;
                gbc.anchor = GridBagConstraints.EAST;
                add(new JLabel("1"), gbc);
            }
    
        }
    
        public class QuantityPane extends JPanel {
    
            public QuantityPane() {
                setLayout(new GridBagLayout());
                GridBagConstraints gbc = new GridBagConstraints();
                gbc.gridx = 0;
                gbc.gridy = 0;
                gbc.weightx = 1;
                gbc.anchor = GridBagConstraints.WEST;
                add(new JLabel("Quantity:"), gbc);
    
                gbc.gridx = 1;
                gbc.gridy = 0;
                gbc.anchor = GridBagConstraints.EAST;
                add(new JLabel("1"), gbc);
            }
    
        }
    
        public class OrderPricePane extends JPanel {
    
            public OrderPricePane() {
                setLayout(new GridBagLayout());
                GridBagConstraints gbc = new GridBagConstraints();
                gbc.gridx = 0;
                gbc.gridy = 0;
                gbc.weightx = 1;
                gbc.anchor = GridBagConstraints.WEST;
                add(new JLabel("Order price:"), gbc);
    
                gbc.gridx = 1;
                gbc.gridy = 0;
                gbc.anchor = GridBagConstraints.EAST;
                add(new JLabel("$558.9"), gbc);
            }
    
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey all i am trying to figure out what i am doing incorrectly here.
Hey all here are my tables i have placed in a DIV for each.
Hey I have a menu(with JQuery) in a div on the left, with all
Hey all i have a JSFiddle that i have been working on with trying
Hey all i am wondering why my code below is only writing the first
Hey guys I'm following the rails tutorial found here http://net.tutsplus.com/tutorials/ruby/the-intro-to-rails-screencast-i-wish-i-had/ and I've gotten to
Hey everyone I have a basic search function here that allows me to search
Hey all i have two JFrames one is my main login frame, user enters
Hey I was wondering if it was at all possible in VHDL to AND
Hey guys here is my php: $x = array(one, two, three); foreach ($x 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.