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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:50:48+00:00 2026-06-06T03:50:48+00:00

I want to know can we have a JPanel with a Layout other than

  • 0

I want to know can we have a JPanel with a Layout other than its Parent JFrame. For example. If I have JFrame with Border Layout and we have a JPanel embedded on it and it is having different Layout. Is it possible ?

I am trying to do it. But this way the components of that JPanel are not showing.

Here comes the problem in detail :

I have a JFrame and layout for it is Border Layout. I am adding a JPanel on this frame. If I donot set any Layout for the JPanel. All components of JPanel are displaying on the window but When I am setting Grid Layout for JPanel, Components of JPanel are not visible. I am adding Layout to JPanel so as to align the Components. Below is my code :

I have a main class, a frame class and Jpanel class.

    public class AppMain {

    public static void main(String[] args) {

        AppPage1 page1 = new AppPage1("test");
        page1.setVisible(true);
    }
}



public class AppPage1 extends JFrame {

    public AppPage1(String title) throws HeadlessException {

        super(title);
        this.setLayout(new BorderLayout());

        addWindowListener(new WindowAdapter() {

            public void windowOpened(WindowEvent e) {
                setExtendedState(MAXIMIZED_BOTH);
            }
        });

        //Panel for logo
        JLabel testLogo = new JLabel("");
        testLogo.setIcon(new javax.swing.ImageIcon("test.JPG"));
        List<JComponent> componentList = new ArrayList<JComponent>();
        componentList.add(testLogo);


        PagePanel logoPanel = new PagePanel(componentList,null);
        this.add(logoPanel, BorderLayout.NORTH);


        //Panel for Button and checkboxes
        JLabel panelTitle = new JLabel("test Wizard");
        JRadioButton rdButton_ExistingConfigurationFile = new JRadioButton("Existing Configuration File");
        JRadioButton rdButton_ConfigureNewPropertyFile = new JRadioButton("Configure new Property File");

        componentList = new ArrayList<JComponent>();
        componentList.add(panelTitle);
        componentList.add(rdButton_ExistingConfigurationFile);
        componentList.add(rdButton_ConfigureNewPropertyFile);

        PagePanel buttonPanel = new PagePanel(componentList,new GroupLayout(this));
        this.add(buttonPanel, BorderLayout.CENTER);

        this.pack();
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        validate();
    }
}



    public class PagePanel extends JPanel {

    public PagePanel(List<JComponent> componentList, LayoutManager layOutManager) {

        this.setBackground(Color.decode("#4E6987"));

        if (layOutManager != null) {
            this.setLayout(null);
        }
        for (JComponent jComponent : componentList) {

            jComponent.setBackground(Color.decode("#4E6987"));
            this.add(jComponent);
        }
    }
}

Thanks in Advance
Ravi Kumar

  • 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-06T03:50:49+00:00Added an answer on June 6, 2026 at 3:50 am

    The problem is that you set a null layout manager instead of setting a layout manager in your PagePanel class.

    if (layOutManager != null) {
        this.setLayout(null);
    }
    

    If you set a null layout, you have to position and size the components “manually”, so try to avoid that as much as possible and use properly LayoutManager‘s.

    This line does not make sense either:

    PagePanel buttonPanel = new PagePanel(componentList,new GroupLayout(this));
    

    The argument of the GroupLayout constructor should be the container on which you set the layout, not a random component.

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

Sidebar

Related Questions

I want to know if I can have the recognizer open while using other
I just want to know that can i make an application which have some
I know that __stdcall functions can't have ellipses, but I want to be sure
If I have a dropdownlist I know I can.. SelectedValue='<%#Bind(AgencyID)%>' I want to do
I have a database and want to lock it ... I know I can
I have a treeView , and i want to know if some node can
I want to know how can we know the other users of Oracle 10g
I have a JFrame with BorderLayout as the layout manager. In the south border,
i want know how i can manage multiple twitter account on iOS in my
I want to know how can a retrieve a UIImage size, depending on 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.