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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:53:07+00:00 2026-06-13T16:53:07+00:00

I am trying to create a JFrame with two JPanels inserted inside using FlowLayout.

  • 0

I am trying to create a JFrame with two JPanels inserted inside using FlowLayout. I have the frame being initialized in a separate file, but here is what I have being called

public class FlowInFlow extends JFrame
{
public FlowInFlow() {

    setLayout(new FlowLayout());

    JPanel panel1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
    panel1.setBackground(Color.RED);

    JPanel panel2 = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    panel2.setBackground(Color.BLUE);   

}
}

Edit: When I run this I just get a blank box, when I need the two boxes side to side

  • 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-13T16:53:08+00:00Added an answer on June 13, 2026 at 4:53 pm

    As I’ve already stated, the default preferred size of a JPanel is 0x0…

    This means that when you add it to a layout like FlowLayout, the uses the preferred size, it will appear…well…it won’t

    enter image description here

    public class TestFlowLayout {
    
        public static void main(String[] args) {
            new TestFlowLayout();
        }
    
        public TestFlowLayout() {
            EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    JPanel master = new JPanel(new FlowLayout(FlowLayout.LEFT));
                    JPanel left = new JPanel();
                    left.setBackground(Color.RED);
                    left.add(new JLabel("Lefty"));
    
                    JPanel right = new JPanel();
                    right.setBackground(Color.BLUE);
                    right.add(new JLabel("Righty"));
    
                    master.add(left);
                    master.add(right);
    
                    JFrame frame = new JFrame();
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.setLayout(new BorderLayout());
                    frame.add(master);
                    frame.pack();
                    frame.setLocationRelativeTo(null);
                    frame.setVisible(true);
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a JFrame that displays an image from a file
I am trying to create a BufferedImage from a JPanel, without using a JFrame.
I am trying to create a equally spaced menu inside a JFrame. By unequally
Im trying to create my own Frame for my application. I have removed the
I'm trying to create a SWING application using Java 1.6 and I have a
I am using a createAndShowGUI() method to create a JFrame . I am trying
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
Ok so I am trying create a login script, here I am using PHP5
Trying to create a black line in my view to separate text blocks but
Two questions. First question is I'm trying to create a simple form that when

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.